From patchwork Thu Jun 27 14:08:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13714447 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2087.outbound.protection.outlook.com [40.107.244.87]) (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 C7479196D9D; Thu, 27 Jun 2024 14:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497390; cv=fail; b=c2b5uznQbC+jYvbuwpyCaS31ib3XzMGvMWWEMx46j6o+88MJKJIU7N2hDhzFWhcHQE4AsM245aSmuJyNBDZPTuvFSDYmw0UHdi/lqjUMMfSkP7hzsIxXKjQ4/AeeR8i7K2OrZCtdOiHgjU1yUwgs5Bz5c3MXjHKSSgEy9Gmswz8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497390; c=relaxed/simple; bh=xq2IlELI39WkbT4ZlceNLx0o79YafrNxSgO2OHvEV5o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fH5TrVfu1ADRHeEOXmEGtYj0UxioXWNSNuP/Y4nOvkFZ0CDqzqbuUyZ6tAPKMGFiEP+iu0FWPbH1iF6fy9Yd0v7vhqwk4xR3D8fnt/MxbjkrPQvI9G1pFgfyWF646hv/pXovphdZKl2MI+Yh8XhAIGq0gJndPW5vzguVMiEu4To= 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=SBosy8yu; arc=fail smtp.client-ip=40.107.244.87 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="SBosy8yu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HKZmtj7Fw+b61CCJtPUKXL388A2o19goXW7g5gCqlyhhWt2/74fkZXV2z6BI1dzmsWiLf8s/BqyPUsugKsHj0ffpOuCXFJI72mzOwgrxIocTefTT1XBxg2KJlCp4sDl4jaHz2hKe8Gg7HG1iR4+S7zcz1QTlJy/uruc17CFE0j8kPI5NhpzrDmHDOw6LD5vK+pHFm7c7/yYcYmIMm3Xja+9KWsPG/tA9ay8BB5N7X7jwFv8zED39gyUFx1mNRfXUXZSwzatxn3MR+DgZW2zO6GTRw2PLpDxZVP2f1Nf4vl4nJ8wPJLk4BmjXbQHSjICSkr+gXV8+gXNVwXEJUZmOiw== 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=CEbNdoS07WybWIYLeIO+mt7P5wkAS4qQiIrfelFW6R0=; b=PWyUn789qcrJ40lQBY7lNAZ9H4/lDg9wkRR4JPlA3WKXXSjcsnEpUkzCW5TX9ZFf+yW8kTfVVP1bu0fROiSp8W66FFbbXnkL7RPBwieGPx0UAb5e/O+S4lkP+h+D9mRzpS2WqrO3kAUrZHKTA4P/V6V7eGxpDAuoX+LjTPbihSaQSQn1xz30BYFjdDo6QnitG7mmqYfa3t1OZ4Qi8WvNKaiWqZZ+Zpc3jGD9r9ta39RhPDsk2khnRpTuEGq89Hct+TDxuNa5UZu0K7gxkrDZY/h5LxloT0UnVe5JiJMLv5GxplhmPj4ro0nvM1Fr3DAeLTGDnXXUsvTEhUx/FQwIjg== 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=CEbNdoS07WybWIYLeIO+mt7P5wkAS4qQiIrfelFW6R0=; b=SBosy8yuxsGppqSB8sJERLEzB0CpqLjWJzVsSXQmBopiY11uvyVf1EqIXJJGoYWkD/hx9iAWDYMV3ZflTt9uZM0Sv5ZBDGOWWBSNRvs05TuQN5JxQ7vv04A2cOoon6THTaSmIW4B+iSN1ZhvPx7c5awQ1JGTCg3yl1Ix47sePTtjFrpH4VQ2i137zeJucRqD66yot+O+AImJ6HDoMCW6sIN0Fok33lk8oIbF064EYiCmqegWQJnIx4k+psxjFxnUNyzN6bQpPBQrRu5kgbQZwahiuk7wdqM20Xamea7GpxWSS0sKorLPqH2VgbGyrqShi3yeKyyjTEXHIFTc9ubWIw== Received: from SN7PR18CA0011.namprd18.prod.outlook.com (2603:10b6:806:f3::19) by PH7PR12MB8124.namprd12.prod.outlook.com (2603:10b6:510:2ba::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.35; Thu, 27 Jun 2024 14:09:44 +0000 Received: from SA2PEPF00003AEB.namprd02.prod.outlook.com (2603:10b6:806:f3:cafe::60) by SN7PR18CA0011.outlook.office365.com (2603:10b6:806:f3::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.25 via Frontend Transport; Thu, 27 Jun 2024 14:09:40 +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 SA2PEPF00003AEB.mail.protection.outlook.com (10.167.248.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Thu, 27 Jun 2024 14:09:39 +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; Thu, 27 Jun 2024 07:09:26 -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; Thu, 27 Jun 2024 07:09:20 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v8 1/9] ethtool: Add ethtool operation to write to a transceiver module EEPROM Date: Thu, 27 Jun 2024 17:08:48 +0300 Message-ID: <20240627140857.1398100-2-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240627140857.1398100-1-danieller@nvidia.com> References: <20240627140857.1398100-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: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003AEB:EE_|PH7PR12MB8124:EE_ X-MS-Office365-Filtering-Correlation-Id: 0da95a3f-21ac-48bd-b390-08dc96b2c8ff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: 9vJZDVB+sxojWlD6h13YBKMnq3/4KMCk9jlnOn1mSYPHzY4XkrdlyP6SoOEsWDbZ5dFLofd02mqd00tz4BYELoRXR/nigwPzw7LSKaKsYAn6KX51Bumj5ZNQhiDZm+sPslZMBi+C98R1oSLdiX96Ocv/3gpFUyz5bkk6XFYlaRBCKnwslGBeZK7dCt4R3cWmFwz0UqGmg7E2MaQ/++cQckzPkb8iJ1dQZfrcbJmodQo0vWWhkLFFtkKWwE/wraKJ11Ajd9vct48iWJOQebU5grjpr9zPd0tcEcqOu9QNyJ+xvXKSAa1RTXfMw7RuUCfhhJ5Sx+cQPxFGHtXxiWqaUcztLXryUxlSkaTxenhg3rtQWVcejpShZGcQqp8wKk6t9ASrz6a6gX+POc2IpikTBUAjSWH7935GGEZr7jETcGsJ1A5E1MkadfnihkT+kmtqRJxC39M0smNjKUuHsOlN1pBIpnBMTXD1zQvDijlY6wvTxFaTBd6+wRSnfIYz/Y8AQbHIkJV7IZjfiJgbj+agdPA+h2YskogdEV71SLzkVwiar/IVGG3zLRG9t/ydD/mEjMrhKPrHhsgHmgCBx2xcuogi6+jVMrsRlkFITuQ6VV30bzL3NDEhOUVQ6n9UQJUSdX70RxVVP4sJSHc3zvYxuI0B6GG+7ezeXYGDClwdvCzblZmoX6+tyLvdfcEGg3L9/DUifP8sQ1IRoygO4KmRM0UY1JuBgjwH6lcrfyAA3VPvcy7KagWEOyBM+imOVXlj7KrnsauWyL/PUDIpdSsQunCbMYNshWTdMGPMRG3xaFWb4C68qOGj1fFAPAzgZAtvpZGgCvrHMXF+E7/UzCzxozjza+8wfBWxiQsXtOj2+gnw5ImZzeOy8gk+LvQpQ9IdoQKI87NjM8fc4s+89NAJQlWjadqe2uwJCrWe2a2XHzqIgVxmBwRATQge3FVGHBqDFYRmw4wzeQC+Z4usag6jvTsnZtsX0xTax1XaM3GnZVcnEbcELHSspVlZkL7YxQZ1jHR9IVbQhESbkOSGMQDc3tOR/AWqUYBDMh+tSpW+RR3buse/034+Urv4AVjC9TvhP+5yYLKehAi2YceYcb6RlApxy0OVesVA97VXiAmUPMOPPlYq4VrWGYYiuYe6eCddDb6WP+YPQEIxuPRSXg05/+ghAh16c9NQwoOcEy/gtfZa/3aVA0VPjMl/yIyVaHKT3OaRbxSW7UqZf4IVLaW5YE5Ih4Mjr8Lj63mGD5ona8Q2VTitHhI7X1cMx86V7MN1P7EP5OOJGDgsRzTOaHRQLk0QjK73vX8sRkpw0pQcwnby6uqaH68HLOlAmq8qmpCh14LyWkSrNgYAzmdTQFiYszQk/m+3Gr3XXWL9nk+pTI+x1tXd7vllfME8oLn5LAbeZrS9TjWTe55b+EAgmLBfA/fpx0ju0ST5AdgoaqfhllqLhH4BJFtRHS5IbLUIvB07 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:(13230040)(82310400026)(7416014)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2024 14:09:39.8907 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0da95a3f-21ac-48bd-b390-08dc96b2c8ff 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: SA2PEPF00003AEB.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8124 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 Reviewed-by: Andrew Lunn --- 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 959196af7f5a..c7f6f2bc9cac 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -506,17 +506,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; @@ -824,6 +823,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. @@ -958,6 +959,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 Thu Jun 27 14:08:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13714449 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2077.outbound.protection.outlook.com [40.107.92.77]) (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 44A6D195F1A; Thu, 27 Jun 2024 14:09:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497402; cv=fail; b=MddeVoIoNLp6jufgifBoBwZ4lAuiOGTleq+vhFJ56JgZPXwMqDZe7D5bUTIeHevgKnvdZRyzPIqEl3bDFPqrzuCoILB8Y8UBEUmEp3/qmtuWgVS4hgj4De/iFDoxPxw2wpf56m34D33QeEKwZ2qZiEOUyYknHJYOmNUqHkzdzXc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497402; c=relaxed/simple; bh=tf8zyR1ijPaAa7uK+SGUvy3ps2hb4oUdo4xjsC8GkDw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VeALocyk/iZQnmVPDqnLKX9+xYUB1hk6se4BbBj7crVKCyTSUqWRRGYCjQVTa2+lqvJn+4XoG773VdJW2oxMKZnMHkWGgXRW12CBPYtV4/nDBfrif21l52Nwk6c5qPMdPyzM4ieEk9mAjLk4qEAZuTXSY+QlA8BwPEPUVtpwHMg= 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=OeAwk///; arc=fail smtp.client-ip=40.107.92.77 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="OeAwk///" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L2ODf/8/Nzizbqg4LVkHgnq3B3/O292ExrCqNcdkk60l7UOS1GvcnzF/EeFUrTtpUoyE1/ZCcC8xI9hFshoLPwZcYY3iSzooQx0ISnZEgj5x9NH47yHTUthtOKfwH2FiRcMo+x3CuP58MmGQ99C7wbcsmO3gkd1XEKExVjLWZiRZYQtvDbW0av2U291hacys70eKAXvY1bAEwvnmUDr4EEm7We6ZlgrVTHq5dqewM16hBaj0++xcGZ1zxMYxz5LNCfSmQ9yrhvxWX/7wiMIg+Xu8P/oA+eRfJ2ri05CNPepVScZKjsU4MAh30NCLHrIQHE05HFE/UzPWiVSBi27DnA== 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=4OUEJ1k/aC0RMnGreZplIUOSVB/4ZfXX8S+AyZU4KjQ=; b=CSZjxxdm1Hnggyxp3zUOKhsUhbUcmcdy0wE7g4vmgBWF1r/8ttRr7eRffWcqui7bsWGEs4nUQ9C+7yZYCfE5nUXubniCPJYdNJ14dBzOk+X8wiWXpmdkfa4nw2o5N2VK/tmxqsMyOcHc4/H7kBM5hCKdVsKLlDRTY1BApIycdTKl30Gsc6xbKMPBwUpl2+22ssVuUrKq1iz0OJ931RgBZ5Ua+A1ZNpe/r4vwKLtuGhjzWnDTd6yqOGR3XQgQ09CgFb2nB8kaLKj9Av4hCs1a4NyV09s/fGIO2ov4wl90QKt8OqEDMUGn2pTuMKsUx6eocYBLcxCh0oBZIhz7/OKCMA== 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=4OUEJ1k/aC0RMnGreZplIUOSVB/4ZfXX8S+AyZU4KjQ=; b=OeAwk///F/t9E2Kf/+sVBOKYvQjqv5GP6+OcVxjYjeGSLAIYTnI4PVCxtZY0TADIaIBX71Zx+UtLeGATqXYCJsiIYGOyozbwZ7qdxUOoV7f2MysWU8p3zP4NmlIkfDN1X5grE5Nll52H5rOD8KLVhE7yQP9ooJC7ktkn68VBQFACHI2lPPHwGphKS9UCd2DLAiyGtCRywAP6pVrNK56cKAdyZeYP/FZx4Vmi3kziCSJxs8GcL3/D8G5rIRNheSeC0nQ/3oGAjxpxHe1GNniPo4ImccENqa3ggaERbxacbhBg0iGjgTYRR8gcDDIbILrWleGt55xzcqJAMGbr2f/wKw== Received: from BN1PR13CA0030.namprd13.prod.outlook.com (2603:10b6:408:e2::35) by PH7PR12MB7210.namprd12.prod.outlook.com (2603:10b6:510:205::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.29; Thu, 27 Jun 2024 14:09:54 +0000 Received: from BN3PEPF0000B069.namprd21.prod.outlook.com (2603:10b6:408:e2:cafe::a4) by BN1PR13CA0030.outlook.office365.com (2603:10b6:408:e2::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.22 via Frontend Transport; Thu, 27 Jun 2024 14:09:53 +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 BN3PEPF0000B069.mail.protection.outlook.com (10.167.243.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.0 via Frontend Transport; Thu, 27 Jun 2024 14:09:53 +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; Thu, 27 Jun 2024 07:09:32 -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; Thu, 27 Jun 2024 07:09:26 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v8 2/9] mlxsw: Implement ethtool operation to write to a transceiver module EEPROM Date: Thu, 27 Jun 2024 17:08:49 +0300 Message-ID: <20240627140857.1398100-3-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240627140857.1398100-1-danieller@nvidia.com> References: <20240627140857.1398100-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: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B069:EE_|PH7PR12MB7210:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e3de39f-1397-487a-2f35-08dc96b2d0f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|7416014|376014|36860700013; X-Microsoft-Antispam-Message-Info: +c4x5brRlLxYzjB9ZFtkaKchFWWUp5KoFnC1dFhqVh9nXlG9mcXIE0cQk85f6iv+z0n8S1jBu7WSqcnKjzKkd63nlBMm6XiLA0ozCQg5VPCQuxqARd7P+IZVMnMeI+tuVMdGBXC7PbswaPHZW5LNPSVGvYUEiFueYXo2FXGgjrjIS9+7GNEflRKMHVzgQqaCJY5JMjaO36SAbPaC+d7+Jhr7fLiNpAXqzYByn6xaNp2VIpmUCH1ArY0/g6+4gjW5nvgXzQNpgnhXH9580tvMwQ5dtZUsWyJ4sgAUp/U4awuIKCKi/zsDCNevuRJrp1GIKt6gnNPz38/gz6qWK3QDmsX1WUaO20RUPCTg5+liHgIEf4clejtU95S2CBXr3xr4hKrnVnE9kLF3viL17Nj7Rjv6HRVdBJvERKMXWX5z5EfMYDiSdu7bGMuh4jfn4yxTEJZgH9o4sUTthUfjSoTS1TGgXZMf7/9FVWK6FB20tqCjloyoCAfNJAnVng9930fvnGYucsLVB32fPTbhOhYDb+mbLwIIytxW+VHPd1BWWs0vQEaokXP23uDAR487viHcVKDIPHmOQ/WFpyDZ2VbB1XGBT4JHWcNmER20vwWGsDozEPXCVblKtvc3EEFTZad7lfKdFINgiWV2NgUS7wNQ22bzcKZyvglecvpuQrmMW913ivkPF4cMq8/XrSa/MkFq10fO1HzfFMKZZvJW7EI20szzOXm2dxoJ7zcWzHm7GjKBMjSti9k/5AIDE58xnVPa56Af2uSokKOoyR+RLzuvaJKMfn0M0WxyHzuzkt/AdfT+5V6dueSNDeZFJWo+V0QUnvlN+o9L7Or6ZkAYJuwp3VLQov7uYciUYltHlZ2HQkEc9Y631o+hk1vzmsrMS4IIlRCSohpng/1miwJgfehhcOnV5NUuRIi8N0DEQ3/CcqMnXg08yCsHVJK8Yl33iWSHgQtNyFfP9Mxbz69j6t9DYA9YqSaL6o5cx6NSZqI1nupTt3S6OHnYo7+NSjHdcrlnTvfMJhNHxN+zVyqLFqnM+G2K/EUzzhSUJ2eQfsvEo4bDyz0WMX7N1PzMfszUx0WeftwNzyhcezBtiD66a7ltwYsW0IqCcsjBdKAkn49lU84qTv0mFhAjiasMpLsSGiIdKsh4uB6nA2D9ZHBuTMr9U0JrtSvqH02NKTcoRTGJ9iGL1EbDrSUP96DT2Y9VOhj1UtB+mUsA4rn3jlfT7oW65tRgudDadI5/2jIVFKYWTgRqTbZzoMpEyCR32bB8VeiSW8eTV1BnWa6qOMmt8hgwkGqN0uJX1xe3S+5hhBoibnpxIqDCQxIOaMJLjcBfP/QNPotsDUJ8crSs3iWuSQU+XUoKrOehB5yHsdcs3fhTRqdW9M0QWwXAcBpUVqR76GExgCyoOx3pITd4l2Iz3flsM/yE6VPReFV8+vaEdR1TIPgvfgXZHZQ582l31g3V0M+7 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:(13230040)(1800799024)(82310400026)(7416014)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2024 14:09:53.1679 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4e3de39f-1397-487a-2f35-08dc96b2d0f3 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: BN3PEPF0000B069.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7210 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 Reviewed-by: Andrew Lunn --- .../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 431accdc6213..828c65036a4c 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 Thu Jun 27 14:08:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13714450 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2044.outbound.protection.outlook.com [40.107.95.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 B2186198841; Thu, 27 Jun 2024 14:10:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497406; cv=fail; b=U7bXggGCyvvarMxeM9At66KAXCXzpYvrlcX7xSq7h7qdeDGwFZ28qWuGS2Va/sppepJTiwFZ4n7YWxiV61fD/X4K3HwgH77/ZqRpTLOzfuG4qOr3ivCKiJP67Dff/V6jzMVYCzV98GhyUyQTpXYchdhUgqwTlY59NOjJ6EcUtXY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497406; c=relaxed/simple; bh=r0+k8ay3p8xkvZG6uKn/yNlLIDpjFoPWRsjPGSROOgk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NHwfgKK0A08o1EM4k8VUwlnZA9RMf/hglU146r99oaFMieMeSVIJ77wX67wIStldUBMoLD/c4dx6RfuCGtf6PLbA0a/uKwTCm+WBnDCBhDSfu8gdvmiFtmcGZ7wWvkLOSCj0Bx/Yka6jACBpCv90sWEc5pgDA++ou+n4ZdshA48= 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=FhlIB3hO; arc=fail smtp.client-ip=40.107.95.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="FhlIB3hO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hGuGTXQoZu2mKV5BBQ+QBV3UIm9CSCTIYLMdyVp0vXBsNKOC8fl3fuigTgVxb6EYjS8LjIyR2Ortz4p+k41M4hBdxy24dVY7yjxrIh1pUDY5hXwqL/VN28/QK4JVNcGeqXxXNcPsmq/EFbLe/KJ5q0Gso4xJARnpBlfZR86KSFYXNPwHSBJ69ym4kZr69oR2rO3vTceNGmx4d/q1l7Fis9ASRs4LdZ+raZNb6jiSUWXi93D3Q5c9hBqNa0DLlWdf6nsI8olpQaqH6v0C0Q7nSoLviZ9huPp8vcW/gv+lt+CoPn7tfUPqBRv8sLsLH+stg/8b1UMWGF7Rk9G27s9qPg== 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=4Uow+unOoR9LoyhBc8qm4AYKD6YRlLdLUOwbGapH0pU=; b=e2TcriOOUtbyd/j6yvx9fU3bAWu/VbZzU9duRtQ8XL8YtrBCJZtxTMFJde1rl2nGibCj4X7BBGUeJSfESB+3oUVSKAhzhDls0UHnaTegfOwR7YpmB9WzHhJzmsYxTelpvVKzPfTNWwTqLnyl92IHf772JmH54JVJyWXuB19NWD6Hcpzp6CGnkhk5tyCzUM07QP3df3Cqj7JsQe4QNVZnXE0t2uQKWfIwvVIiHyiGNPMNRWEgF+xWlobNeN9O2YruPq9r5IMo94VX7mNys8HLmxwwQoY7ssZqNlz4GDkXY0fET6VjIzTh+0quu6cRd1BJ9A7eyk17fzWIjg2UejNzMA== 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=4Uow+unOoR9LoyhBc8qm4AYKD6YRlLdLUOwbGapH0pU=; b=FhlIB3hOfaVxm25ZtLKFvXs6j2C+4rxbbmJdNna5qnu7t1+aqBWB75Ei3GpKEN4xV3IJUdCOONgjTWvQ/YGJf4tQUeFi+270s65BCI0qlxuEnOT+rMRH1jytR4g4qU+hXnv0Bcxl7wpZifk89x05o9zw1/KOVN74p2p8CT9qrry/0wnd6kocWmXSRuKigO9ggRjGb0qypOu1wqon9skCHzkQyrYeRO7DorwqoiSmU0o61wkeFmdL37HzvAJUBxdTUSQ7fP/ZTuG9SU+NK7Iz9Z5VD/9vB8P901nfL/nPK3B/pQ7Ss3EBANPqNsbSuQ2ATg5CsOqTP2h7NZvceHGxCw== Received: from BN1PR12CA0017.namprd12.prod.outlook.com (2603:10b6:408:e1::22) by SJ1PR12MB6148.namprd12.prod.outlook.com (2603:10b6:a03:459::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.34; Thu, 27 Jun 2024 14:09:58 +0000 Received: from BN3PEPF0000B06A.namprd21.prod.outlook.com (2603:10b6:408:e1:cafe::15) by BN1PR12CA0017.outlook.office365.com (2603:10b6:408:e1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.26 via Frontend Transport; Thu, 27 Jun 2024 14:09:58 +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 BN3PEPF0000B06A.mail.protection.outlook.com (10.167.243.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.0 via Frontend Transport; Thu, 27 Jun 2024 14:09:58 +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; Thu, 27 Jun 2024 07:09:38 -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; Thu, 27 Jun 2024 07:09:32 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v8 3/9] ethtool: Add an interface for flashing transceiver modules' firmware Date: Thu, 27 Jun 2024 17:08:50 +0300 Message-ID: <20240627140857.1398100-4-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240627140857.1398100-1-danieller@nvidia.com> References: <20240627140857.1398100-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: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06A:EE_|SJ1PR12MB6148:EE_ X-MS-Office365-Filtering-Correlation-Id: bcd1563c-d5b2-4afb-3b9e-08dc96b2d3eb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|7416014|376014|36860700013; X-Microsoft-Antispam-Message-Info: HZudfULnnF5m/oWYjuR3jHSQfHy1X19VC0VzrVc3W/xOCLrKI+JTsFZTq5vdALePpp8SunRegN1gHDSu88GT1BSRYE42lecOdPt4kuoP3ZwtnNQduIgPYgVCKvimKyljIQfwV2xugIMQWbSw10V6+bg862UAeU3ZjjiaTGMjjG/gqPYKIKlO4UPhgob1SNIqNKtHlwZiQGpL7aiSEdS1vSw0Ut8+nXlL9D0Yf2FOVn+O8BgLFV9aeQsJWPQ9grbmYlKcbCLfedIOJdx3snhnwGfgmU4eTSd+11goG4lg/vbkx96rnaRzVKyggd/os8/+5xkDlZ8d4RgHDgIfM8TtapQD66Hg6MxzVUus4o8/Ppueh90nnsIemndm+RKLtqOT/NZWrjRh62U2oD/Xmj1L9w+3yVfooWAAeUtReTPyxxTqUnCLE0jOJIq+F3GcVEY7OzB0RWI1cKrCDnRo/g5W8IVxr2hGMfa58O974aa1jaLdts8Nr1Uz0o+ncmkEGBu6TLy1tazlwTISK6BICR0ec7Up4v2u5LHiie6mF7cvcVyCXBl0zHQgoi3hcmRah9Q+y9Umfr7nbIhAFCXRavkJZuFLfoExa6lL6npX06ipPcXfAUdvYUnaAt8nrD9X0Dcbf8nSzqM4UkIUyYAArE0ZT/nERPVyV7ju8jtrJj60mBk4EjwwY/CgYenagm91XxZ9Cx96WKA51qb1N/1VIr7ISjweYq8aw5ssnSEDF20ez4CSlC0mmRXfsLn7aQ8SNlSD/bZF45yGy5nYg87+gXSAOHZ7coo3Jj1oFCBt1gryLYmGMP+XDxh/1doWj6buX6JP9WfMtS1ijiNjdCWz5+3L3iIG/5elPJbNFipv0z+zCb01Q2YSPsNMHYYAMEGUtqjRzJ8vSkgflmWrpcTxiZv0wAZ6UJ1ApU3LKNkxtD+ZniKneeKnl5Az6iLK4+q2h7lnRQO2qQVF1TUzoI0qxCs283wzhbAJYIu/rmNYWD+CH/PawXmNIMIdrFvuODW7YsQa83rbXnXFURxEVzIKSjmMnme21DzRGEgMYBVJdBbgR7/K2qCfIB1li0135BfYoFviv/yNHY21fncEZBPeaWDOQQezksjPOHH7oW4i2C55IHXPv0LaERseujP4/kRViaSDW/AYXJKI+kbyXnTVivKempBmATxxjfb9huHJFPVigre3C0mDSnxHeIdse13tQVwWOuaykfwSTB/rvOhC4Pv644eGkKjHAQ/2HEuXrqEHsKkRyQwUMCL5Ko2QdUqn6gXLyXPRFFydVdnf3uXoIliXoXGgw+zDlTwe7PP1EI4NI0a23bZkBFK4PjcsByH3PrQi8vLMmbB5x/JcUpNpZ02S7uGVV8jLP4GXGSAExUN+mExW5Q+ltAZHkE5+Vz653qfX2G45b9HD9SC3Yh9wloZz1aqqFLA8+SVW0JtmTtOvbt97JuZ2bcL/pXNvXlURvwdq 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:(13230040)(1800799024)(82310400026)(7416014)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2024 14:09:58.1334 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bcd1563c-d5b2-4afb-3b9e-08dc96b2d3eb 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: BN3PEPF0000B06A.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6148 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 Reviewed-by: Andrew Lunn --- 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 6c2ab3d1c22f..05bc0065d439 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: - @@ -1004,6 +1008,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 @@ -1761,3 +1791,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 7ec08e903bab..bfe2eda8580d 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 @@ -2041,6 +2043,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 =================== @@ -2147,4 +2216,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 d15856c7e001..840dabdc9d88 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, @@ -1018,6 +1020,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 Thu Jun 27 14:08:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13714452 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2054.outbound.protection.outlook.com [40.107.236.54]) (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 9BD56198A35; Thu, 27 Jun 2024 14:10:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497414; cv=fail; b=JbuWoK/iwaiUodshYbv+sqA1E9EqfWBejdTw3VDwvC4Ul4XRl7i3RVEL27dhPkkDe1QMC5OpDSlceRNYw5X2fQsttoFZ516F/LAho1JDY5Oe5uOrlDl4gnivmbz8QT/XX19Z/FpGa7q6QRwFjvXbmI5NG9pJYb4atRLVwRhBXr0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497414; c=relaxed/simple; bh=NpEE0ls9XQHFSXMiHmYkeNcLv0lEEe/RUnAq61/u23E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=upusdUgZHtFzrx+59rIevO4sISABGftk6qgWW4EY0+r0TKdRFn9BK4n5781Vg0jnICZNRoVYq3eKOpY8d4VoZnWlFvI6dajY3hMp6veKa0cZ6erMArN1Y7W442ZX36JKTFcjgm+Gw6xYmbsD9913EuDgM7PGgJv23JH5LIFx6ko= 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=Of65Kjac; arc=fail smtp.client-ip=40.107.236.54 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="Of65Kjac" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HG236lXFjYhrlH7R6+V5Zgg7P7xLZI3Oi7tFFY9tf2dl50B4lHKyqR0EdV18qGLZCCXvxBBtajCJ9bE14TO9pHolzaArWpIdpAsIWw+G3F935i11HmADySeOorpsWCnIDSYx61hAAy+mv51GxkBV9KSlvfeEXcqtQJ1hxlZHv4xLPMmy1nnp07wf6CXj5tfIqfyNRM9u4tpY9bBapBasI3okj0zb0WZaD0iMFMfopxh619RvvUCOSNvKQByHBWpXnupQ85NRL8ID3cUTzBHBEfK0Z0e/kr6Zj4dDkZkeulPK9AnFjDIgny4CTyERUEFZktZK7EkF4pAU7JWk6MHa8w== 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=lVyEvTMWPzgG42wVdEcliSwmDHzFLUOue5wVVlomkSk=; b=LecVJV/tMiTXSLrzdZK85GuHkDdc11tDjXk36DwRZ/jeUZbdpVdfplMGdQM2y5oo5AFxaYIV2KD0Sp0SEyNRE9hx6KeuROKVigNb8zMLPKWomepOah0P4E8bRgEMQxDafpPLuLMvxVtr3uvBU02D9SRvwb++nIKC+/nG/FJlDPpH0INYB1WoCYl5qSfTfn244KtSE58jJevdpke3FVD6YJD7k4ojyNBTEUEwfRSDC+K+PMcRPF/o6kdsW0zpM/XtEWkeP0ALTEAaZSlnMYrmj9NlaLXTIke3f8/ksOywpHz7YuGJu+71jEbU107Vt0vSLu2JD8uEoOAzlKPv8JTdrw== 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=lVyEvTMWPzgG42wVdEcliSwmDHzFLUOue5wVVlomkSk=; b=Of65Kjac2b0ZpzY3Ns6tcqicFKXVksKBXR9YvNmc/AOlXmV5JonVYUdC9POoWTsQhVpR6KPUjO3gJge+hF+v6JP7mYr2dPhH9HF+lTCUZ+qIjaPrHnD2d2gDAUPr8mRnElQ2tKXlEAvvhcTsqLmHhBmT3MUiNxqooJGlysIeo96MqURb0uLROoHZKhpdR6W7amBoeOBh1ujLNLhSXNi7JDFP5/ei6n8oCkaVCi7osHxx2Lj2hp2A0b0h2sKQ0TGGhEV7wDNKGSclu/tnj+Ati1dTFM/dX1MoG/5+8CHf/kG6UiToMFtq782QwXE0+9n1Q8rp7Ia020BixVTWjEhFFg== Received: from BN7PR06CA0057.namprd06.prod.outlook.com (2603:10b6:408:34::34) by SA0PR12MB4366.namprd12.prod.outlook.com (2603:10b6:806:72::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.35; Thu, 27 Jun 2024 14:10:08 +0000 Received: from BN3PEPF0000B06F.namprd21.prod.outlook.com (2603:10b6:408:34:cafe::8c) by BN7PR06CA0057.outlook.office365.com (2603:10b6:408:34::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.25 via Frontend Transport; Thu, 27 Jun 2024 14:10:08 +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 BN3PEPF0000B06F.mail.protection.outlook.com (10.167.243.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.0 via Frontend Transport; Thu, 27 Jun 2024 14:10:07 +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; Thu, 27 Jun 2024 07:09:44 -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; Thu, 27 Jun 2024 07:09:38 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v8 4/9] ethtool: Add flashing transceiver modules' firmware notifications ability Date: Thu, 27 Jun 2024 17:08:51 +0300 Message-ID: <20240627140857.1398100-5-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240627140857.1398100-1-danieller@nvidia.com> References: <20240627140857.1398100-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: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06F:EE_|SA0PR12MB4366:EE_ X-MS-Office365-Filtering-Correlation-Id: 38bbe570-9c59-44c1-9b5b-08dc96b2d99f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|7416014|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?fV5vz6qqCjO+CW662gJtJTo+tTxdPji?= =?utf-8?q?/BYS/oNbQ6vfel89yoXIiGX4mVv4qOnfaTbfKxVvZz2Ox2gX7DCxM60UlOVO+icw0?= =?utf-8?q?oIKUxx0O4s3eE/pjAakxM8W5+lTzGYmd1s+Uz6LNomewpZb3yQM4wlj4Gg0qXASxX?= =?utf-8?q?WDYFz2mfrEQ7JD3/qwyG9+4NxQ74K1daIbaL/+JNem2Jscm4scc+96evo3dk+ZKQ0?= =?utf-8?q?tubSv9yK3OftS9/Q+ME7WcazvXZp9tKfUzW2e9VKZrSJ+l9QsBKfETPZD5M4I+M3K?= =?utf-8?q?Rtwo7HEeDK260QoPM0i5laf7ezfmtB1Rq1Mjeo9gCkGx83JOO6L3k3qCIyHm6Ps1R?= =?utf-8?q?w/EWBhQRKhf5P+PWLDV/scoIL3dWFAYIZZF/T/ydWcgZxj/VBk26k6gcRzOk2k84f?= =?utf-8?q?cZEgCZJehTqsTjgcLj4/Bci2DSvUvq9qIi+hkL1nrIgPjaZ1CNoaCT/2sJwMr/D4M?= =?utf-8?q?vPnc766fIuFFLuvmSPm7MprmC08wnFLT+C67qbyGcaHsJEOtUJQygQz76sPoISDyx?= =?utf-8?q?0UJgc180iT31+NcVrNzPGe8tTuJSldPicwX3eCt3p+2kRwv2A8aupa7ce3uoHV9id?= =?utf-8?q?g7wo73jzq1TjkB5Pimy9CyK5/FadDFWQVWh+7fW9MVfw5RoDjfFa8SHHqJhGB3h0Z?= =?utf-8?q?0saI9wCayVYWf7YD0VQ2wEzSKwfH0/59tZPrUF0ECsVwPmEKcGlKhXOfcGTxhqXko?= =?utf-8?q?Tm2Zr7JXcfpRwUWL9d1l6doyfJwfmK95Rpb6C94LV+Vr/zAvsJDxVY7wNvDSvilTQ?= =?utf-8?q?+QZthOmX76VbyGsZCb+Ys8PiRK//mDENVNlfoO9Vgwawp2LnQPegdGyxS4Oc9USm5?= =?utf-8?q?KOu23iviz3K4RP/Kxs1nMIlcyTKFoqlucnDwQAGoOaAWiqbbZEsatEno6Sfvqoy2F?= =?utf-8?q?z7MJNkhl53krbY+Vj5uPo4qHNBvETfPE7LB42i0I8/rkK8t+509rCDzeG+ZyrPCdo?= =?utf-8?q?lRy98/PsieMQsdebXUkCDKuH5ZT8ZuPQuP0RvsZaV5sIqag6NAgNENmWDmc0vINea?= =?utf-8?q?oyFqn6KxSEHG7xad4+H7lS3BSC1h6lg6LBiAORUthYuHwiVCnfnyHb51lAf5vWis7?= =?utf-8?q?oFrwRuRR90+kzHVR1+aQ1mJmRKOmWfyUIOuz7pqO4o3XdElj4OaB4geQHT/qdNd03?= =?utf-8?q?pKHteBUa+pUhkUfVmVOjpdZH8TryRj+fm36gkVQckVeV6fqH8ZVH0apMmb6Ey+BG4?= =?utf-8?q?5tR7Z8kQP7XzIuAq6tUszYk+8hvKDUGkFWdx7kvTpfYoPVU7A+OiIk6EVjv8w8Kv4?= =?utf-8?q?CoBbIC7Bi5Ung94Ez2K7VFiLfIPQkEENxUzaL5TXuEfNKh2+XenkgUHhJzqhwp7W7?= =?utf-8?q?BBUTnSMtPEctVbo/E3Qw+kTpsLXVea7JaEmZZHkO7W8uxIH9wXxBCSF+no8E6BtAK?= =?utf-8?q?+QtSDXpNa5i?= 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:(13230040)(1800799024)(36860700013)(82310400026)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2024 14:10:07.7197 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 38bbe570-9c59-44c1-9b5b-08dc96b2d99f 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: BN3PEPF0000B06F.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4366 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 Reviewed-by: Andrew Lunn --- Notes: v7: * Return -ENOMEM instead of PTR_ERR(attr) on ethnl_module_fw_flash_ntf_put_err()ץ 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. 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..ba728b4a38a1 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 -ENOMEM; + + 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 Thu Jun 27 14:08:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13714451 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2046.outbound.protection.outlook.com [40.107.243.46]) (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 96621196446; Thu, 27 Jun 2024 14:10:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497410; cv=fail; b=ocDd5vNw6hgBHj3mIV3EzaqPdMoG0EwuhBJJGR3Cdttw9oBbdPWNlDialRGSQKSqA1xW8GBgvPu8z6m9G48fV/pzCMeSTKxiCIsN6QZh85BPrhg+owAEf8IzJHb+pFwW7dO8tpoa1l0J26LeD1cw53jRSPZ+oyd02StG7wqumko= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497410; c=relaxed/simple; bh=F32vPIxZw4R+tVUf3f3aQxhqoM9YvVNcWeSJ7l/lx3U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c8GSGamWyXXpx++TsGpCo0PgwF14ssNRaBSSMLte1FkrtpQ2fw4MbArMrIAUj8ljyD4+Uyh/BD1yVjGxUuVzkVNrKszuRah1NYBeKasEQxzbYVdLi56c2hiGmXbRescMm6mRrNSupuQhj6vzsZBmvl2XUbGhOh5kERw7/V5l+pM= 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=cxT5/+ug; arc=fail smtp.client-ip=40.107.243.46 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="cxT5/+ug" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ejyIi61BPx9LPCArF/OBVTcM6V58TwqHz0s8XeFPdarv7na34Kabj8+QINk00d5VACqbj2SBhioVQJ02EUUXJwu+BrIqK8tTn/UXoEfvYGLhm5rkOrGkRLDAcCoRKPW51lmVkcNV8V5mL+cTYpD6VnMwN0fk9IS+ARtagSp2GHVp5vQ5AojcbyFNA6qkpsPCjrJe8jBWd9tgKlhADjmfXz3/NZMY8e5+UeX7TlOyhQLHARmf+UtUSgiVakHvb6jfHN3EnDM24/aPvkATF2TcBW1ftaOI7MEKe4eXAtnECkvqGSvf5yYZbmFCfueNxA1Og0tTXhe9yaqTBTwGMjqPRQ== 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=g0x9M4bDBCRjTJ2J3ocOJy0M8j1SiN9GVWWPMirmQu0=; b=KmisVEf000xLuEljTROEHGOVYEIQ6RzizY8kmtq8CqX6jQwn55Z2b/gzdLOvUjFG+nl3O9By7crO4K107S7VRAslTu81HCD24Gp07JYOXNm/w5WtOGWIpRMOVyoXMbILzldH4M3XpjJaGDVTUKo3RcR2icUhKttI1hd63Jvm8nlkaMq5akP0N9Cu0as9l2CBWY79/txb5NnvBcLxgtFvwcx+qxAIujTtjggexdRW/0miXrKQlP2XjBzLYc8J1Q9AsCvhewgb2+jEH5pHFYzfMWt48CG/KDfImTrcqXg/OwtjATJW2lzQ48uXA+j0ymWdPYcTrYGJXMd/Nb9EfdblAg== 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=g0x9M4bDBCRjTJ2J3ocOJy0M8j1SiN9GVWWPMirmQu0=; b=cxT5/+ugLSxCiUixVCXgytmrmlRzMpIUbnJlz9ksmKr0fnDdfUy67w1HWDORcnq8T4E01Qc3Ml1OwMY+m2KsxIeMI1SfsJIDbYCnL7An6dr1hmnosYY5LO3bqHusxgq4ehGt4D/HMzKQjAOEyXqFPAi0rsBOAWs7NSZlwu8TpvW1WX2h35QcNZ03DYlx7fVkoTX16PVXksiq2AnaITcOxpLGc1gIL09XqlTpnJk/ZzU4cIdkf+dLeZL3HD5USdacKPje3SWRicnuE9+saIXRiiGPYX0tmKkyOf4IZtwQbQDEcuZNhIJnWhxjHvUJPPshnodfo/wCOya0A8w3FPkkTQ== Received: from SA0PR13CA0016.namprd13.prod.outlook.com (2603:10b6:806:130::21) by CY5PR12MB6407.namprd12.prod.outlook.com (2603:10b6:930:3c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.26; Thu, 27 Jun 2024 14:10:04 +0000 Received: from SA2PEPF00003AE6.namprd02.prod.outlook.com (2603:10b6:806:130:cafe::84) by SA0PR13CA0016.outlook.office365.com (2603:10b6:806:130::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.20 via Frontend Transport; Thu, 27 Jun 2024 14:10:04 +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 SA2PEPF00003AE6.mail.protection.outlook.com (10.167.248.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Thu, 27 Jun 2024 14:10:04 +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; Thu, 27 Jun 2024 07:09:50 -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; Thu, 27 Jun 2024 07:09:44 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v8 5/9] ethtool: Veto some operations during firmware flashing process Date: Thu, 27 Jun 2024 17:08:52 +0300 Message-ID: <20240627140857.1398100-6-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240627140857.1398100-1-danieller@nvidia.com> References: <20240627140857.1398100-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: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003AE6:EE_|CY5PR12MB6407:EE_ X-MS-Office365-Filtering-Correlation-Id: fc7a68be-33d8-4607-f585-08dc96b2d791 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: y8UGWFjh5ZlvCAfBaR2bmeAACV95OG5/+U9Fc7Y5pFe3TKq11BsToLLTVnvsfxBOQuLyKuiteKlp1YCPtBMu//JkIQa31uk6IrwmKtosj0cFO2p0N9mLXcasYH3uKINUoDLyMfBWeWubBOrg8G9Fs7RJ2I3F7sPnty/UiznREwW17MDNwj12rk4tAbMcVKATJ9ired2CnYaHaR6SVkIBOgWKYzjihEEgoInCDNsguIVPPYsom80I/QUujnI2nU49Tt1BJQcgDr7UGEJ5Xbnwg9sBcLeLzB978jUbVNFfSy6jor7jYm7qq8jmdlADOlVVrFgstfBaEDa01uR/rZrAN+zz4SX89vHMO0d9gL/1DG4imDtOGerthotQ125+gTxkzxjrW5+Bkli1MMv6GI1W81FN1TOAM13Y/h0HLSFdyD2QSpKT9L+AMPaw+QHP99RUv7L8gIrdi94qy8eEQGBqYtbMesTcFppsc6xw3oHNMYgTUwNmNHpUmhXEsVYK1SeCiJ/nuWWfXu9ghXB3UAn+J6sVnf1kW7Wuh57k67eRLCteWiw0erUBylM2Nwl3V1b+Rt1oEFsMk4H4ReNiJ0Y/k7pysC+k7HkyKWljfC9xwDiEOmtFeCOrPvOwlAylJiPtLxY3A5ryYGMshVTfSnDDhRwgo3NTizie/8yG6iKkF4s/GHtxMD9tHl3FyES+yuHsykthGDAVI4bbSt9HgVoKp4MLPmHkPgBpYJnbHHhZ9bjvoanMuWYSVuEppe2N4sSzJZrDPTt+HuOO+uY8tweRlf72iMx0Nzy/8yHrHkAI2OGsBCy5txSdFsTKRnHaVro0xgDc8YLZHfSgh2y/LYMVs56NBHeTDrLFO8zjbbd9EDfs7BzLAl/Z0eU+qwhxis+5S6IzAtCRSyUUwvP5gfwH7RwfEV2UGL88zebYVpLsqKhziCw5c1l0TnvlvKJUX7syhRFZeWCiMi5giob5TC2QHuF0xRH/OL+tI4ljCqNUkz8ZJ76MVq77LDhv+GWokl0cICWSbTPlnD4Nw+n4paauNnS//yb3sJaD7S6fxOifCEqpPv4dVmPXA14eGOx7zjB/PkROnkl93YdpeV35z1sFP3Kl6PHo82jzTy0x/VbY600MRJbG7hUThAxPnQAxhEQ2NrIesUmytXqWnCi1Gkk5LR8vXA8QQLdLnFtAcsgm5DW7DrbRREYWsuN+T4gB5/KVNZxMxdBdLeDADEz9WEsr1dzOIOS6XF7blxHd4avfZbDY7qc3rjvflZ8DpFGfxRc6nIh8xy5b0Vg7bR9016A4pGmER+ygk30a+DwbM6wv65Ad4LkNe+F3mmISz8t9rmO3ALTgKZiWZDFcmXOCekCyy0ryheu1dexdZhrJRwnPn6aOqI3eeqtFGN9/0T5XW6odK9an3uBMX1xhFHxclbE2+iZmkvBtOjT94GNZTmSPe4spE3nYP6VLud3IHlYf1tqf 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:(13230040)(36860700013)(1800799024)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2024 14:10:04.3373 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc7a68be-33d8-4607-f585-08dc96b2d791 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: SA2PEPF00003AE6.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6407 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 Reviewed-by: Andrew Lunn --- 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 cc18acd3c58b..1e3401093c13 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1990,6 +1990,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. @@ -2374,7 +2376,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 Thu Jun 27 14:08:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13714453 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2083.outbound.protection.outlook.com [40.107.244.83]) (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 D1BE9196DA1; Thu, 27 Jun 2024 14:10:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497423; cv=fail; b=R2PG/hY5X3Lft0nSx1mQ70epIMr/fKvqX48p/BnMPzwNjmszN8ga8yDF5Ab4QrvjtgoYxNon1BAh0ddeqjr1s+mrTDmyaoxEn7uRgi9js0T2x3I7hVDmNc8/DFH9Igab2G8QRyJvEM8vnPSfpadkxcSR4P2nARujFXAERRTeBPY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497423; c=relaxed/simple; bh=0JhTrYFbPQxEms9r0XrDZukXl5JzEjsCopD23qbYXa8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Kay6D6CLlb8BYKRRe5m7A9KXgFj61eCY//3BsYvAxOef5PYBYzx0Ap1550bVDmVDT9vPCcL2ZqnDpUV3Q0LuJpjG6LiI8wQRMIskTgpgPG6W0aomg0PKzr659JCt0umbhUtja9xvjhNn1LCJm0TeUZobZzlt162Qd1EOfLOIvxU= 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=CTTDhfx8; arc=fail smtp.client-ip=40.107.244.83 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="CTTDhfx8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EggZtO3Bu59hFMlFb8NT9/IV2+2dAMKzkamYHYo8bTpHsOqa/CdErOEWwZqTRfB4Mr0YPYZO4sxxHtzP1VbMZ+mSTZKM0XDqQ4/PG9ztk+ZFYzyNSpUGrVPMYuQMnXdYwozoicJ6xSfXYNSUIlNs3rzzDVGPVko75YszhSovTmxTVeRmu5B0IZU72bYtDkFEHGWjX/LYWnV964f9BpIEO5vxGFbp1gH2RYF5M14+QXp9kOW4MF9MHGuywQqatpZg8nurtkc+Gg6zg8hjiyG309STIoR8ZHMWsb1gziK9DCD8wfIlzPI3NYEDnLn9VGLrWrSL1TFZgi8vyebygX9Dxw== 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=iSNRGgCQeNloOWnF4uwMX4k2fWLjpvEPEB4fqvrE/GU=; b=nCkxqchdUweSE6T6sHCEs1SCpFw882faj5Ogb/CPLv28M7OhzORX/lJ+1OzNjLB0qtIA5CfE9ORf2++9HI8CKbzB7AKPCK2+al5UROIp/0z1OYzdIiYuavezwk7McXyHFg8gW4p/8VFK5X0Zq3EI/HjmZIxlJEn58AnpH2iHu7T2BRhMZmVUcsDr00do45fKM+nF52GQ02ivlsPhbHXzxKvuPpBqg16ys6FdmbOAghxvkFRFHqG57eBaULW6uShtNMcRlHh5bLUifZqfNJhvXQw+/sx81mXKa0R5IVEI0jJhxXKUlJB1xjX6cywn/Ekq5TTfNgYRSItIFfJv3Y7D5w== 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=iSNRGgCQeNloOWnF4uwMX4k2fWLjpvEPEB4fqvrE/GU=; b=CTTDhfx8EeS6Ku/jjXC33GSLD/wDtbuLTsK0udJFnaLwOxgjeizhFqhAvT79D+duD/A97e26oatAr5zDc2DZMvO2bMDe5bAHN6hccr+i2/8GQ+9n3qg/BTXXKRGFDLXc3rwt5taAfuQhkgxGkDpGGMmu4XXhDBWu3X4oUCiGoyHUyyJVPrF4pKa0TqWLBoQAxDZzmZlqIt+9LwDpsV+fqaMKD4HcKTfI50jzzVQqJc5fdzQf82ETqpgkm+O0Ohs5CtyaRcLRrTZ6dnqbZ5aN9bpLnT34/jsvHArnwMfihaTm5xWRQM+hD3V9PoqIEP92TIOV9ujzhJEhmDm54EByuw== Received: from BN8PR15CA0071.namprd15.prod.outlook.com (2603:10b6:408:80::48) by SA3PR12MB9225.namprd12.prod.outlook.com (2603:10b6:806:39e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.35; Thu, 27 Jun 2024 14:10:18 +0000 Received: from BN3PEPF0000B06B.namprd21.prod.outlook.com (2603:10b6:408:80:cafe::70) by BN8PR15CA0071.outlook.office365.com (2603:10b6:408:80::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.26 via Frontend Transport; Thu, 27 Jun 2024 14:10:18 +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 BN3PEPF0000B06B.mail.protection.outlook.com (10.167.243.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.0 via Frontend Transport; Thu, 27 Jun 2024 14:10:18 +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; Thu, 27 Jun 2024 07:09:56 -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; Thu, 27 Jun 2024 07:09:50 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v8 6/9] net: sfp: Add more extended compliance codes Date: Thu, 27 Jun 2024 17:08:53 +0300 Message-ID: <20240627140857.1398100-7-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240627140857.1398100-1-danieller@nvidia.com> References: <20240627140857.1398100-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: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06B:EE_|SA3PR12MB9225:EE_ X-MS-Office365-Filtering-Correlation-Id: fc0da56a-7d8b-40e1-3f1c-08dc96b2dffb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: VANWpRb+F9WXfq8Vjl1BQh+uxt5Dg1nZzCYwvHN9tdGi8z1eOaJfhgPatPEcNY2jWb+/bxln59bCa4bFEmL9yQi26xU6gUp2STmudX/jdxC5hKd5Uyt4sqm2TQ1FPjvdSEM2P2cufh4vSjlsPztW0W8ej0YVKpmTuwV/ECGrDRbdW5+E/u/b4gONl/2Vpx8JEU6r4SFswf0J8Q6NXwFy5iIhhuEUDMCn+5Oy+glQ/p2MOmAZDRx/Ss6KfD5sYYHw2kGFgXewPzjxcTlBhcsgdrk1SsiJkPlCHG2mNyyJSawLMYC9KyJWqnh/Pd0BAI4DGcqUK6eomVhfbuWYoAiIVc5DAbvfLLr9IV6kEtBbJAN0qiH+JMRjQV1N6SeM8R+v2NY11jl1iea4K8L8qDkaYulA80zpYVQJD1DW8rJxTMMR7UCNQGl5Kh1eZhPatjbXXLwojlEdaALrB3pHX8pv1wwBdf8zYI54/81CLmscYpDd4xp0+RWi6MkIafY9II9yepfBc8YCjU7qDR7bgnxlCxj4AYS7xwgiL3XZprX5T6QhG/NlpZszKlrcaJXCMmPd7axbG3sxhQomlAmDtuKCjf9T3Pc96HYMpGZz4HJ6G4abwR3CLYPojIFtvGpyIVhRx3jjMLb9IOe5oLqbTvOAU21SO7Znx9lEH4uloVlXQhK2mkaNqVhObwsE+ewXSZp9CZHSgchQMT4p/r7pv7AlVTogAoQlJfzt0MDCZ5bNcpTyiiIlebl1z1Dtdm4KThoxFo/+MY1sem82538bnAz8z09cl2ROFMyxizQTlM6jpMhZU6vLgyWcaY0eqk3rfgOEGk8hyZjB7Y/b9srCdwz52Owp44VQ8eo/qDvbE6POpkb99odzzZwEzrnRjeAhYbdMoWPf5O6B0K1pu26hHvkxOa23ldaUvxm3VxXRn/keeUFJsCO6dqasU9+FIinUVX+tq+IwmjYOUhDrD9bhLj7C3I/vGK/iY8nl5ES7yG9z2Ps1pO/ZbmKAnMLCAXSUR9cVvfPOGLRsenzl3AT6WlbNpimp2wB/CiAEC1GnW/7cvJTEGrTNqMJmwDrIYcU1zxrxlc1shTJV7dJS0mRJVSwXfZRUbD0MVGRzXWs6ZFKEvCo/surqdgZ3aKWo0kKG0eFQo2HNuqeuCeabYPvrzoAJsRMxk45TR9BPqEfXi9ktrRVYvsiHN3uzr03zstWCQt++IQYyda+a7vjecCdrmmmzSmFUaSuZmQ24bWkA5qitedF/byOadvsosgKc0rrjAAb74O2y4rod1ki+MeMG+WoCOIwgS6uVk5T2F3mAtmhavurgplPgZ+CKTJ3cpdaX8tqeLvk6N1ZUYZ/VomriCRvt0Q9XcFHbIB6QTcUAp0WTdThlt6r1JCF7AHgazqHl3R20yHLbmoNOiOfCTM08oaXcNQgAG/wCjZvagpTjqzS83aONySZMQe29T6MBksx66zrT 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:(13230040)(376014)(7416014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2024 14:10:18.3866 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc0da56a-7d8b-40e1-3f1c-08dc96b2dffb 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: BN3PEPF0000B06B.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9225 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) Reviewed-by: Andrew Lunn --- 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 Thu Jun 27 14:08:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13714454 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2051.outbound.protection.outlook.com [40.107.244.51]) (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 D7938198A35; Thu, 27 Jun 2024 14:10:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497424; cv=fail; b=GIVSx1cCSwdMLXh4bVOwmRKelqr0tigdkbUE+1XJH+5X3G6YlDe/YywthLxYqeTtUMUzv588vopjjrwa0URykvfwHXLLzHqsfQESi0Jxl6KJP2rB+zOr6q72f8RFqfOUA0zBzF8AdxWnvrwa/gV5msLXCV6SjCSINojEkMCfWOw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497424; c=relaxed/simple; bh=EpBFfkvMkAdY2RuiTZoXYd3H+AJsvoo8Gacjb7UmoSA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YylhdvbLimx1h69DyPqcV2KMCAH+1JNDZQwVUf2CbF//PajjIK8/P08j6lhYdYADiWtEQOokTablVQnfmz4zjcipgE7iWWmNZoq6MggBg8fDyoDnWkKTR86VTa1QcH9jK061rzjfwfwyrsXEbhMwCexU7JuLsN1fPF8G+B+QB3U= 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=sEBw2bAz; arc=fail smtp.client-ip=40.107.244.51 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="sEBw2bAz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QHuHrqsjLCaQ4tXwvsH31Q9YLQe0TuAGaOb5Jgawr+8JFv1z4wsZbv8wi2c5nKHlZTmES4D+6HWn0QXdDpEpAaHqg4KjByQ8RT16gkuu/ADjh+LO2VDV+c4gIJRfptPyqOsY3wQ/TzYJy/z/DJvqyj8JcsAc/GspYbGAQTN+U9Tou96U1LbKrJfycRsgBIj7HqsqvGQuVEHDmKim7W0/2ebdtRnFSMhJb6gEuQxaDuaCaPwdfnO6NwgCKeDe0KInhTHxtrVVmKnHlZiTPIGkXJ/iPcU+FfUpmW5yAN4hWzwSlOt1dOVY3Fz/+kBKskKksgwlyaJcFR5sDLvXj74vqg== 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=Cw5eU1A7+w97S+3ix5ohLCiqJgrrbyA78a56AYfvjpE=; b=cF6bwzCmp1n865Na4fpNBfRUZGl749Tq7p04dTB+bPtzs7cXlEfHBZPRmdd0BoDixpApMSdBS8Pnu/SiH0bYIkF74r8aSw0O9jQCkodN4VvLNy6wEmHX37F9PXUKoGEBMHVH/T9o+KyriBVY8MF5r62Hu5rUPI1la2rlsyuFhlALVPG1DZVxfJTqw/rR8yrAW10iWcbrZKt3qj9gUYPLMTL0I7J2kVsWn9CslhbFvBJJThIn1yYzafVUivOZiW9zisqsxAPVBA3hrA1xiQ70xQ5ycHecxJsS+zKvcMEttpmJXGffOnJUWfgqAiou2ra9gCS+4rr0KYQgPrbRZABtBg== 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=Cw5eU1A7+w97S+3ix5ohLCiqJgrrbyA78a56AYfvjpE=; b=sEBw2bAzflKFJka8NAQ0dxvNMezH1uVRW4yRrUoxBPt7aDmSrpZocjQo4EYBLNARnFckb4evkheVjw9EQZq/MJSjFfzvhCa/lrXUPXoZhAzYjcrzjixyqQRycytApt3wPue/zbCwG+BnvI7WuMock56ITXbiFm+t5RzT5jeAjPseL0FcCPeUc/VbghmVvLWN1FUsjdoJiqRO6KrV1Qm0bi+bb3VFdVgAW/hMqpTOrp4UKcE8++wAwQiM8dInucOruZK6B9PeHENpWvCBf+hNALV+U92DgOpxkDv8gVj6mLGK7TgO6Vh882I/KYdh7RFhQ9Nbmx/wVeuBWwJvNYP72A== Received: from SN7PR18CA0014.namprd18.prod.outlook.com (2603:10b6:806:f3::26) by SN7PR12MB7810.namprd12.prod.outlook.com (2603:10b6:806:34c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.32; Thu, 27 Jun 2024 14:10:17 +0000 Received: from SA2PEPF00003AEB.namprd02.prod.outlook.com (2603:10b6:806:f3:cafe::c1) by SN7PR18CA0014.outlook.office365.com (2603:10b6:806:f3::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.26 via Frontend Transport; Thu, 27 Jun 2024 14:10:17 +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 SA2PEPF00003AEB.mail.protection.outlook.com (10.167.248.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Thu, 27 Jun 2024 14:10:17 +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; Thu, 27 Jun 2024 07:10:03 -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; Thu, 27 Jun 2024 07:09:56 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v8 7/9] ethtool: cmis_cdb: Add a layer for supporting CDB commands Date: Thu, 27 Jun 2024 17:08:54 +0300 Message-ID: <20240627140857.1398100-8-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240627140857.1398100-1-danieller@nvidia.com> References: <20240627140857.1398100-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: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003AEB:EE_|SN7PR12MB7810:EE_ X-MS-Office365-Filtering-Correlation-Id: 3dd13ed7-a311-4a48-9e0b-08dc96b2df5e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|7416014|376014|36860700013; X-Microsoft-Antispam-Message-Info: T8654Jb4boW1h5Tx8ngvtlHM0Ugf5f/YwhMBR5rIwoj1vYzgsWfrZjNHXtjRPwTTPxNx6O354NT7KPCXxj7fbx2AO6SEgoiZC1sASk2ioDTHU/Sq9gGewep8WjfUaZRdMUB6oPBjgyawhO/II9fxEYgRIvWmAkzWMpiKjcSNFk1o5Vd9a0jvb9L1ICv4lmVleKpH8blWyk5TtsfWcjyNMd07jAvgqeiSPUx0ig9TKaaAbiJ/n1uu7X6URO0qlt9Rgw9C/qOubXBeYH4yv+fFQklC2sIjntWiCNsLF8TWvq4yXzzb62mFhnCJN/tzTu0K0wxo5XlmpAgv67XfwiUb3xZPhrHs87ZOHrU0/4EB/2PHCa/nMGdY6yU+p9yTZp3Qq9VMdqoc9a3sFtyOLGCbBWyKwgs1gWr/6jr+tSKVpXjnBaYbTmTzZoFll5aIh3u7SY5wRGWu8EAQRi6mxMj5JSXGvJTdXGN3tZT8EHcyCjvttM7MgeRvlOw/qJQ4hXOAowtRFocL52YT+G8zVP9XDgCElgNvjbe9nshLNj4wl1XH3yCIerfY3xodh9+YcgdGcAYDAQztAYh5FbD1MltBUKPBzKkCgG0GXbxW7rlHNlQ/ignzL4WODQ7dDcvK/GXoDqj7JJS80RJq1hDlcnKIVUhst6X3YdtcAZPpSbDFgx5cw+x0ukEZ3jOrxVeuhQ1ph3ELX4i1ACZhCAgt8VT7JJIyAs3PwBTsSAgQRkaoA5vE7tYOkb/v+mCBoB4tsLS2wH+91iAfTVLCnFNQRflhTuYnTBRBFQatqRga5qAmueYCr/yI/N8bNDIApwg7Lx4VyTE6B0jkFX3+zXyK/lHUonv/1+tMcryjv2qghwu47YTk1r6nvPR5x59MZyngtq5qGwB0XbtjJdKQ3ynnU/82BB2XMSKgA6vxMLx70tmSOAn0v3FniWfYnA0JnZ7VdbZnyEySceRdpqbizztaYEjjbRVzTc9N0muYUjAW1vjXcjrhwrTl4zSCAJZz6xCgCqTW5vqZyTxbdOW4H3ZsQloQuAMdNy6TfKO8kB8xVy2/Gpjp40O3hj5EppdXzQK+77p85GdjlMNTIOkRvNqhnNEyhM1CU/vDrw056yagKN64W4OWcX602tIBeLKxOidWb+0alNxpo09DMXaZ1STJxXNGAaVQbvEQwfBM4SVlXNdXHi1nY6nKaRiEJpH1Mw1CA0wIQ4odnIuSJ4bzle0jjyYWac0DV+duYkLkphkF6PTp00Agg+zJPt/Ns5Di1FtPjTXCCZNWqynk5NEy86aqmfbxdcwrD/U2zQTY7Z3yrx8IWpqiGJuY8/4gBTNTIfNPMvrRV6dOObLOVqFNCIzYb2SKtH0W3/Ts6wrcktpbj5Q/i5pmV0DzJu1oJUFx1tfg3B1/rANCXuYQRWtv/96fb9qI/A2OLoLxmXyU9yL649z7wbn2UjjC/owoUmhdiO7MnieL 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:(13230040)(1800799024)(82310400026)(7416014)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2024 14:10:17.4226 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3dd13ed7-a311-4a48-9e0b-08dc96b2df5e 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: SA2PEPF00003AEB.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7810 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: v8: * In the ethtool_cmis_wait_for_cond() evaluate the condition once more to decide if the error code should be -ETIMEDOUT or something else. * s/netdev_err/netdev_err_once. 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 | 602 ++++++++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 10 + 4 files changed, 730 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..1bb08783b60d --- /dev/null +++ b/net/ethtool/cmis_cdb.c @@ -0,0 +1,602 @@ +// 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; +}; + +static int +ethtool_cmis_module_poll(struct net_device *dev, + struct cmis_wait_for_cond_rpl *rpl, u32 offset, + bool (*cond_success)(u8), bool (*cond_fail)(u8)) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + struct ethtool_module_eeprom page_data = {0}; + struct netlink_ext_ack extack = {}; + int err; + + 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_once(dev, "%s\n", extack._msg); + return -EBUSY; + } + + if ((*cond_success)(rpl->state)) + return 0; + + if (*cond_fail && (*cond_fail)(rpl->state)) + return -EIO; + + return -EBUSY; +} + +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) +{ + struct cmis_wait_for_cond_rpl rpl = {}; + 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 { + err = ethtool_cmis_module_poll(dev, &rpl, offset, cond_success, + cond_fail); + if (err != -EBUSY) + goto out; + + msleep(20); + } while (time_before(jiffies, end)); + + err = ethtool_cmis_module_poll(dev, &rpl, offset, cond_success, + cond_fail); + if (err == -EBUSY) + err = -ETIMEDOUT; + +out: + *state = rpl.state; + return err; +} + +#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 Thu Jun 27 14:08:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13714455 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2082.outbound.protection.outlook.com [40.107.101.82]) (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 87F851991A5; Thu, 27 Jun 2024 14:10:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497431; cv=fail; b=MVLpPu7/WLalgqa5rWcbOjgn9bnKgBmc3XMH1BLfvt0rFr8EgyUj1a1AhSENOmNdxgKwRlHu7c2y1+afPB076p3IiPtu58/OqYGm8kspvr0PrUnOVaRuMVNlHYoOdZZWHbbKfaEQQeHxPU2mUdpUA4uwPbPqoPHQYah6tvaVVJ8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497431; c=relaxed/simple; bh=RqZrtF9hzPPydnCat2CKUJoLjAR3aJkQL8WArZqek3o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FdbARYmyIyoz3TohFfvv33ihIAx9r3AkdBPyUIPHv9UJz2oymF4/a5m8qGhFbKaO9hoWTREv5ZHNU6nqbC+eZ0MCgERMe1dEHYyIFsrLtHekaWa5RCHWZkp2irz0iMBIlXy0IMx3itMBVKn1OR+odaHoSnUnAW3hLQXO9Cilglc= 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=EkRkwwuK; arc=fail smtp.client-ip=40.107.101.82 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="EkRkwwuK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dd5KyC+Xs+ENuYxhGBMiqFWguWfVwtAutGPO2Bthy9lB1Po4rGghGa8wKROrxTe2tCeCDrFL+DDDCgEOqT64XStzdHfpA/CoExcX7RgyJPfC2R4od90tuo+iAFZz7aVdepaVamWxkGjjNezRvlN2UONjYZpNTMV6w09OgQHdaHaEq/8CnazFMHfRj5MS64N2nHusp7GfsHraYklbD+9biimqEDUraXx8oe2ohYtTvi6DPxICD0GiAV2BjGgxnuWo3CN8uN1UkQz3yIxljBnpc6O9ewW3abzLFnHF86uDbM1bovoTP6HJKc+B3dR9wviWbN5OIBHnVhNVjp6NKue2Kg== 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=YW9nd2lwrpOENLR5rwJEiEN3RaOZCCPAADRCpj3anuKbOitM7w1rkEyapk/9jdpH2e+x4TbcyqJkMRx0kAQJpW0swIQ/EFaWiHH5uhQmthiIiyosIJLWczgLU5YKuZPOp3bJL8LcHSLckPpu/11T9uGJ+GULsijy0kMfIatIK9JQSGBlNLyoDXC2XPjnuT3Ai7Y5lGAuCToWpxf2pRHU6aKa6ZxVsmGP5vLeXEIVLgh1UNZVtnvtU7uLMJIvzb5SwwSswVTDkoYGofFdWXdiwsvf7ptGaWvBgfvmKmFpiZR/Z/gmuhm9mfAqOfNdpYOCMEBFrg9OaAibRflmaG4ZmQ== 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=q4khK5DkuVZdWTbZsjigRzdxqODND9aPqXhMDUBlsPI=; b=EkRkwwuKug0JbKf0dWHxLAzzOCON6joDy0EMlVgBdqF19FfbNfK6ZzGlAGvqhiK754V7jkdtB40+onCk9qO/vzLsjaHo0ZqhdgYZ11uZ99rtgtgEb05wFS1P+DIRwVcJx4vGMfMoHfrxrS0d7Zn0qSLW21a3WfVQptky2os9YRFliyb1nPdfahI+w8iAjYLyNQFBx9QcJ808LpRandfRxz7YhRXhVVThwUDa/2PjbH0qjy2hiSjG9SBUyhRvGeSSRkeZymEzoYWyR2C9u1jW+HeUCPF68MiiJf9AyAw/ev4KeTSwG3SlYbQxXlS9nUeCEuZlJqKn7EXt3Nv3n3Yq3g== Received: from SN7PR04CA0151.namprd04.prod.outlook.com (2603:10b6:806:125::6) by DM6PR12MB4434.namprd12.prod.outlook.com (2603:10b6:5:2ad::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.35; Thu, 27 Jun 2024 14:10:25 +0000 Received: from SA2PEPF00003AEA.namprd02.prod.outlook.com (2603:10b6:806:125:cafe::70) by SN7PR04CA0151.outlook.office365.com (2603:10b6:806:125::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.24 via Frontend Transport; Thu, 27 Jun 2024 14:10:25 +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 SA2PEPF00003AEA.mail.protection.outlook.com (10.167.248.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Thu, 27 Jun 2024 14:10:25 +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; Thu, 27 Jun 2024 07:10:08 -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; Thu, 27 Jun 2024 07:10:03 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v8 8/9] ethtool: cmis_fw_update: add a layer for supporting firmware update using CDB Date: Thu, 27 Jun 2024 17:08:55 +0300 Message-ID: <20240627140857.1398100-9-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240627140857.1398100-1-danieller@nvidia.com> References: <20240627140857.1398100-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: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003AEA:EE_|DM6PR12MB4434:EE_ X-MS-Office365-Filtering-Correlation-Id: 2844cf55-c2c6-4e66-b8ff-08dc96b2e3fe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: Oh9b1AUqbkhF7nklnOgOPYwJOxARf11Jq4Z1hrd6l4qIX4v7IVV/UJr5F/lqE8P6wNoKgdoCG4Wdaceeci0tqxAX6T6QHsyeV17MbWZZiYh0/A8pjnsDtutO6M6lvGqlsaVmtUmLhUIEtIOTjRDKWw0p48Jlon6sGTeOMCq3TeQFsOlT8vA8+HJPuOp3uIkpbNvnPXJfMWxwiQ7vw75jT3LkYwb9xggUc9Rhcbm4VBAuPumuNyp4Bc0THxSoc8cSokAZ/dDEdQi6r9kFpgscK4BbGPnGCETvBW6SLN7xPL4PtLiYSVjHeHLe3nlbRoowu6zvmMs0yDtvxp8i0SplYtKbiLTxijnNMIwa9mmDk4tISMmEn69O1rQRG4h2twqzkPVQxndK5tp0olktKnaP1WsYrefSoD3CoMomakTUFBd5B9TtNgxBf8BjehY+fvbZy5+8uTkTiziWRdBqnkNHMeRcXUfplxwza0hiv9Om9SF8wD8QXvxtnjS80CA8ycYLvRk1rUsCuK88EtEB23tfwE+6pStjyIRSsi96CdrAY2oUzOkYqP0OOiNWP1FdSSvT+R9zuZp5Z38M9Uih50ow02ZjVJi6MxofzY2bJ1rU8ZSgCUwujWMDOtf2K1sY3YjKHs1Si2o1NL2LDZyGSa7lSBB8/8uz5bW92iUeEOWRa8TmRzkhcDPbhWGQZ1ZgaiQKD0/B78XChpzaaZ7TuqZCRh5kWPSuFtXskkGfkQ09GY+wNsCpI8OESgPSUefThAo9XD0vx/NcuStGFnKhtxKqnucAZPxBYhcBFqxGSEeo4DY5WqgromIRijg+co9lrxKCnhBWBxM1iYxGZk+RA+24zjCZ7VHmIjIHJfleDkzVBJFDpFS7u+zb36w4vl+4T3Eha99PPWXsNZLhL9DtWshbOWLRHuJUhCxs+KACvoyF1i40+SdhZgoOvgauYFeCh2F43kXgAvGXbFxNxPg89Kf9CuplzvURDNS1oOddha8dxPLDV1M+dQ/EuQ96Hlwf2ocqCHeE+9S5Xhp+nD4SBBYccx9tOaLB6PLWtuKEHZDuItVFGs718LjMbBas1NESog9mHIvOJjYfu7QgWYE4EAGYGN0VJhKjUO4hPqQrnduI4BHz/8k1GN/i/tt1Aw+rEvt/rhP3pXtix4g7sE4WkfTXvc84HfmRbUcwPfq7jjzdFdrcXvTr9pZLtz1FP/3jjiEipeVlXNs/Yv61PlxoDgYGdzSOerAAZTggDoqlllC7/3mCezb7IS28o7RrxyqbYPbnoQ0TLI0nI9qtYvyprqUTiaAmdBvvMX/DdTe11hIhITQZ1AK3M5OyRm9Nz18CCBxJPY147+L4T/k+f4NfLGsEUL9vK/TEjwrGr5Ku7HqKpcW9qUTVtLg4Pzie7WXbH42GY26yC3zeWsv/b5z1ZOEp4Okv5uS0yI4cnVJn/W3hE+KzvIxTuvN9L7WG12gK+LJb 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:(13230040)(82310400026)(7416014)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2024 14:10:25.1828 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2844cf55-c2c6-4e66-b8ff-08dc96b2e3fe 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: SA2PEPF00003AEA.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4434 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 Thu Jun 27 14:08:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13714456 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2055.outbound.protection.outlook.com [40.107.223.55]) (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 D481E19755B; Thu, 27 Jun 2024 14:10:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497437; cv=fail; b=rAkmf8+uvrEC/EoZXjmGPlHUM3ZUjOaHqlTdBVIorIsVjTOCsqqKqYvVz5Lf6UV6Rd6tY9PteFY0iNPx+tNLbY4o1wj5tEdbslbbiOHQGmdNrb7ThvWkIFIHEyytJgy4uDNtYBx3Ba5uzp0x/sEWQ1uf5zF/TjF8Hg3Y60VZ7nE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497437; c=relaxed/simple; bh=EbrTRw2QVpnZbECqTUp0JQ5mkBSP5fVoau0WvgbYGfM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hM41a/hKGDAzYh9+lOcIAyfzPb+pTPvNDxaYQiFCVVWloqf1silVWYWm6Vsq0KAaqIByPWhuo7UZY72hsli4taVVBxw16qh1/Sxb/WQ5gePtCymtM9FDGBCFAkGyQAicUpV+IKyx2rIBlsoTAOI817QpGb7U8T1qP+PZf6Q3TOo= 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=K78tEi/h; arc=fail smtp.client-ip=40.107.223.55 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="K78tEi/h" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q9/wq57TKcxUQo9b8ISS0UNrcAlpYk+3yOt80xOqwnU/dzx8OoDS4Old/zuOcW/tpMRZ0fhLEjkx2UKhtuNKba7KNCltBZrsYCwVYHofCiz1Ext50vySBn+Wj12HXRRnicQGcykL1yIrWu1zQAJUAzNO1KVDChqrVowfHJEDJwptR1yG7DB63SaNW7H1dPnj+t4sX3uYy88ME2zV39VDOPos8JW1/1Eh/blc8hh9NcbKs8alJ3mex2T++66Nh1AY/gXd/fghAoqka4371j+etYChWyMGXkwIz+iOVH1FDfUgcKvJR0xJu6R2+7H4xhmkNDMZhPUxPirujFSbb7e7vQ== 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=rzchNaUmuyi+LzuK7zc08C0wU4TBOPk7rrAs3wfO+8E=; b=ImYQyW+dVRQ4QFgjzrZUokTOzB/7xCtkwmcABuYOBLodJwaCpM4lrNHUo80CIk8nnNSAQlpJUdsPP/9UGrq9/qDeILZTzdlfWc+EusJ6bFjD4q4KhO+qnAjN5YAH9tQCLL0XzHz/KuZl/XMExXsGMLR7nSRIv8Kri42z2fb77SU1a/HIu/iRrZ+kPjIHDYv16/NnTeSW5v2xI0SJnB4LveNX8uMcdp1asHOspk57JRJt/iGr2kH/ZxQqKMolN8yhD/hvXMM4IL58S+RUHr9W5jZHZWSCFY9lD97ae7BXKK7VAP4EcYn9SYgpTN+tm1Sp3bX5xvvxkE420dlaX8jYgg== 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=rzchNaUmuyi+LzuK7zc08C0wU4TBOPk7rrAs3wfO+8E=; b=K78tEi/hlQdez5ZavuxnupmJGwOwknG/qZsZ57skt/bS+ekeWojjWOBpzKwCBfiYXgnLj9qzsGlnBaA19pQmWZJWFIXyla3C0oBUhDYoz/Q3w5G8Z2W17WW6ZxC9UDupNs2I1LKBw1O8SLPWaLCxKxeWrciVJozTeEN6rZWl7MH6dIFY+hjzp7ZY5HvR3//wbsjCwgmCVEAA9DrlOj3TjHvAyO2prnPWClx9Xjq+BLq0NjdrbdGd2aczsB0liZUUaircDnZuBw1mxYkdoE3go+mXavehDaRmz7KGQMhtU29z6rTyHZDjC3Y6Ht01BMr+220caBBBVsNm3ILu/lFi0w== Received: from SN7PR18CA0016.namprd18.prod.outlook.com (2603:10b6:806:f3::20) by LV8PR12MB9263.namprd12.prod.outlook.com (2603:10b6:408:1e6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.35; Thu, 27 Jun 2024 14:10:31 +0000 Received: from SA2PEPF00003AEB.namprd02.prod.outlook.com (2603:10b6:806:f3:cafe::ef) by SN7PR18CA0016.outlook.office365.com (2603:10b6:806:f3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.26 via Frontend Transport; Thu, 27 Jun 2024 14:10:30 +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 SA2PEPF00003AEB.mail.protection.outlook.com (10.167.248.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Thu, 27 Jun 2024 14:10:30 +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; Thu, 27 Jun 2024 07:10:14 -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; Thu, 27 Jun 2024 07:10:09 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v8 9/9] ethtool: Add ability to flash transceiver modules' firmware Date: Thu, 27 Jun 2024 17:08:56 +0300 Message-ID: <20240627140857.1398100-10-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240627140857.1398100-1-danieller@nvidia.com> References: <20240627140857.1398100-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: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003AEB:EE_|LV8PR12MB9263:EE_ X-MS-Office365-Filtering-Correlation-Id: 1cef1cbc-2a8a-4783-e7ea-08dc96b2e73a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: JDSvf52o+EEPo8YgCUARwaGumcygFos2utqHGC8glgEdmV0MTXIKmSoHdTFmdH7BRWGTjAWX+LYDEqLkdyx1GuxsZDKvFIVLO6sIXD3/ovtEW3swMyOkFjiFL4oxaHsMgJo8VxqdvAQ7ZdwN43Ge5cdsClfywOqjhDNKoEdkuVNDdWzeTqVYJM6PxKbxKzHCqJ7CNm+G/YSJSiCm5SjjgUG3W83EDyg/MDK+giavH7ARix0u26heKOR7grHTzplgZHaYSmIt97rMsN94w/5I9va7sVJShBt4Yg8fsuJxyfqAFNNRim9VbPOMXOCdrX1CbC9/NQCGsNqhdKYHcAO79HoGB6VyRzGJKxmmjW/Ql1tW4hkKw68fFXpl/A+e4UwVuJ/fWbdx7bRewoMrHMfVLaCVxxcJi+tkZJrqZviUUZUrYclnrqG7GKV+ImdvyvIarUMZ5TX748A75ptEFhEGoVKdoDPvA/9XW2R/zOBZ4wpH7n19jr9alj/T52ulHvZmVjpJfKWsS7ylWzfiq2fjLFZm2xwfOVaa7/p4Yxq3lcA34Uk18iPgbqbVg34NOJVgjbO6uGrdPdyzSLc0Hd7/xJcncIFp/9Vn5VcvGime6kpH84ru0FvVk1B7BU07BiSP0oIQ1/ZkkApCtd3cengsB3eyV/7x2AyNYhOoBK78OTLwx4z8UklYlAbUfK+4y6VLsoYCsVoZZhqfcRf6mhO8yMHD38SVHjw6aoRfSm9ItDM2YVceUbAdLqxOFizvBYuOrOvbveF8+c/3WfJXAbJiSf3m/2TXF+KLs+tofDFz0jcsFdTiZMi1JnWbbcGERq2K6X5gPRgXpUhsGj/mTcGD3aNCbtXxGuHL+vk7GWvfjupd0vzoxiEQB7PxUA2JQO2vLmdhq+eE5JpIoUCKy9z1uQT0+6wJZlaz2A4M0zA9i7RZGAVJdkE4eC4vU2gS6/zYdsvsQHmwx2qyt5d4Vs0KwtrRMZOfuW643oomkRZQIopLXdQXgiA1ngzGsTRitlQTT7gPFO7n8vVRZon0r/SEWsCoCNXlSN9cZZhSO4gxHJ2hjCEFW8um4Z3JK0lc5CsaYUBaPjV709g91Y9o98WwRSanvrilEwjJRZWIFRe6I6my9YVVBWQZPVdV37lcmehnWHD0kxsDoHx3h2AsPXJDguXSVyUJD1N+vFnGOiFYVOMi7CJbpq/D979YQ8YRWJluqdvXIrHzJzS5XmReCDfCsD9vkFDJvzaTHcFvB906hPt7tL+TeAi4+eSG8+WLcRt8+XvknZEtU8s7TS3t7WB8qKVlYKVvHjoZ+9KZLNz0sztdBCEY2L0VPn8aMFPBqHq1sIFLEb42qwayJQqwyzefc+IiLHX5g26h5qXiIe64aDdzZ+JcQ0eFzO3d2rgZ7aK4I/66az0t5jK4reY7/gbVaCSHqDzeUI2rkkswSpejLIZA80oEtvwLj7V7yLF2Tjrk 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:(13230040)(36860700013)(82310400026)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2024 14:10:30.5166 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1cef1cbc-2a8a-4783-e7ea-08dc96b2e73a 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: SA2PEPF00003AEB.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9263 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: v7: * Fix Warning for not unlocking the spin_lock in the error flow on module_flash_fw_work_list_add(). * Avoid the fall-through on ethnl_sock_priv_destroy(). 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 | 277 ++++++++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 3 + net/ethtool/netlink.c | 39 ++++++ net/ethtool/netlink.h | 15 +++ 4 files changed, 334 insertions(+) diff --git a/net/ethtool/module.c b/net/ethtool/module.c index ba728b4a38a1..6b7448df08d5 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,268 @@ 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) { + spin_unlock(&module_fw_flash_work_list_lock); + 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..81fe2e5b95f6 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,35 @@ 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); + break; + default: + break; + } +} + int ethnl_ops_begin(struct net_device *dev) { int ret; @@ -1142,6 +1172,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 +1195,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];