From patchwork Mon Apr 15 12:07:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13629880 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2048.outbound.protection.outlook.com [40.107.212.48]) (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 D77C266B5E; Mon, 15 Apr 2024 12:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182889; cv=fail; b=FcRk9FNECoKLP4RMknJNd2haTZACTfY4vX8+wfJdTtRmFx+78u09idHm+X0mMHpSXxwMzAb01pE9sHJggTvOEAT+q8Hemov4P+MeyqSzRLlXxLHZpnixKopFIuep2rgXTqKgzJUfnrvCRDwpJVJ5YwPUWhG/pq7DerVH9SQy/jI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182889; c=relaxed/simple; bh=485yKaVzFw4bNDXfnNhUc4xLloZouKdblr9Y2t97zhk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MDKDSnLISU5soWS5TL28hIdMZHA2pZ7cKn5Ksp0M/vZyhy26PJPVK45bPNxxmCHsZZ6HG5buN4yt9a3EceaiTnoLecVj7Bw+NO5ZsQGKzqGOW8/iNLBG7e5BrP7kZyndPTwmddYJm13a2nqQHtjAK5hGl4hPdmVZy29/AVQKE0U= 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=ibj8ShjB; arc=fail smtp.client-ip=40.107.212.48 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="ibj8ShjB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YjSSpDiiyFpgGarTnxyh05ii4yii2l4j99sxfBtRNOTNutYwbhdWECF4v09q/cArmeISHu1DOpY+ylv96kePT5uhw6XitPRKEbanWqKUdXyFjM6i22YzDN4EJ2nVhJ/r5AicTsMuCMFyfZ3AGWJtZQe7Sk9yBgGl2fC7AYwYOdP0hHzSR2vVcfQNwg77wreoiYfHf6N7hW4OlEwCSgccdizExbzi9Frxpx/Zv/BUlHwCOzfIb4n3Py1ZzDo+2eMzNHB2rqOmGFLaU50OQIwunxJPnsboLCQFoiBIEyPhMOmlSnCPXKuuOiH+aFJaerLc/rHaZEhVs87KZ/hE98XEkA== 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=nYDEuo5q5plxK/stzgXDSSj2K0u5JO6eOsUjnC3tZ2M=; b=XhOV0NxjrhDeQhYmv8gWorMFjgdkA1twiW0QI4Gsw1nORcoy8R+Qi2CyhXu3FC0XOVpK/qYeI4W8Br1BCYywqooJdYf9Tm8FFZh4h483506i+wtm4emaeDfvJKO1q4foo5cZZlz8R6AfKoPgg5CZ7Mvt/Kt8VeGdC1Y32xg2PCJLlrRFD0RQlkvP01yXNeelzWS6Zh2D6Rsu8jW3dhcPO7Vbevp+vhjRCH+tNBdc18mSakQplSrR3tVQJqPJnoYq/mFLX+Be8mWmMrPuMry6ctf3JQBgmH6S1t1AvfBmT7NJTivut+D/tBGMC5LDb2JtbcK5d27s8kby+Jm9/xNCkw== 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=nYDEuo5q5plxK/stzgXDSSj2K0u5JO6eOsUjnC3tZ2M=; b=ibj8ShjBEfYU87Oc/lKpWUjkUX5azC1dZWO8oxXQjlRR6NhadnTDqdPm+0nkSqLKmSXpfcdPFNR0DhZEWhNH0wsdvIcDULgtfM3fvH+aNq6NsR7ggurmpkZk7vlKA/EC8shdEWUYlkt48DQ7QrtDvQA5sWaD9PUibv9Ey/Pw4ZxVLMjEfm19YY8qSBxADEVmZ5xRJrsZi4n5sbvJNWai2hn4l445VI1/aaTJSwztnO+g8jCDdfs0szjgkJ9WbmZ5TjecZSzim7MPcvT2UfMX1VbD+eL+Xpuuu6xXtW8AqSBbBhUrn9BYy0NUDulCmYNEQI752L/yy4DUpRfjG6HASw== Received: from BL0PR02CA0087.namprd02.prod.outlook.com (2603:10b6:208:51::28) by IA0PR12MB7625.namprd12.prod.outlook.com (2603:10b6:208:439::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.49; Mon, 15 Apr 2024 12:07:58 +0000 Received: from BL02EPF0001A100.namprd03.prod.outlook.com (2603:10b6:208:51:cafe::f1) by BL0PR02CA0087.outlook.office365.com (2603:10b6:208:51::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.33 via Frontend Transport; Mon, 15 Apr 2024 12:07:58 +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 BL02EPF0001A100.mail.protection.outlook.com (10.167.242.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Mon, 15 Apr 2024 12:07:58 +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.986.41; Mon, 15 Apr 2024 05:07:42 -0700 Received: from dev-r-vrt-155.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.1258.12; Mon, 15 Apr 2024 05:07:36 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v2 01/10] ethtool: Add ethtool operation to write to a transceiver module EEPROM Date: Mon, 15 Apr 2024 15:07:08 +0300 Message-ID: <20240415120717.1251864-2-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240415120717.1251864-1-danieller@nvidia.com> References: <20240415120717.1251864-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A100:EE_|IA0PR12MB7625:EE_ X-MS-Office365-Filtering-Correlation-Id: b4ce435a-158a-4f45-d4c9-08dc5d44b0ac X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lXtPlLn58tIvZBfA/8HbDB2K2eNQDjjKiODrHBCUeDKOCPtU4+0OVnrR3esgGgyQ94EuMupOHpPeIaNHzIZfGilaIRLqF2k48EO1WomnnATVew0EjtSv69oRmP+VuSQ3Lii382YWB6b+RImzHxc2Vgm6zUEF66okKcCxdj5IrnTZjBnuRQ2SiZe0N16/89HizMkwMwFyXP290EsqQuSDgK1YdkXMXa3AquWclhSQUshoBA2nYperNOsXj8N8Ntq/nH5KKlrQ4T2KBMGl1vzKyovxe0s60v70kD+X+o9IkvSl4f0pe1YksN20rctn6f2+NRnmHmP00qiCcyo/NrBRdxMNv/gPUjdjAxru/h4w3+QWRlROrBPK8Em5CxqvgIhBIPO4YXcBtvWBXsQD+GpUNiabPvUkLH9NP+zYVsX5gVPzXKi8yPcF6M7MK+KXjG/SAOmvNXgpy5wQFHe9Ma7v4uhxs4fvxlf9q44OKoXGAvjEoCz4mgJ4KvvGcv+9Q78o/gehi4GKm71DcJNkrxdZlBsgW6tSbsnAvNu5laITBqVvD6wym8UvJm4X7jjFZQ3RZ30pJpQDuX7wid3x4V2GtB/ORtUO6Lg1423R54mRhUnThg8CiLv35y7ilkWi0jv16t5KHgNB1+dSSft6SbKzVmu6AeqGmx6b4Fz9w5LeNAp427utVezlP9LSmSmXAJaV9aK/hliCQsXkm0NZuGKvFL4O01g+jjE7t9WiTeL0p5eC5P7rho5Q/3hTkSCje6rD 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:(13230031)(7416005)(376005)(36860700004)(82310400014)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2024 12:07:58.1012 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b4ce435a-158a-4f45-d4c9-08dc5d44b0ac 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: BL02EPF0001A100.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7625 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 --- include/linux/ethtool.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 6fd9107d3cc0..fa1a5d0e3213 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -504,17 +504,16 @@ struct ethtool_ts_stats { #define ETH_MODULE_MAX_I2C_ADDRESS 0x7f /** - * struct ethtool_module_eeprom - EEPROM dump from specified page - * @offset: Offset within the specified EEPROM page to begin read, in bytes. - * @length: Number of bytes to read. - * @page: Page number to read from. - * @bank: Page bank number to read from, if applicable by EEPROM spec. + * struct ethtool_module_eeprom - plug-in module EEPROM read / write parameters + * @offset: When @offset is 0-127, it is used as an address to the Lower Memory + * (@page must be 0). Otherwise, it is used as an address to the + * Upper Memory. + * @length: Number of bytes to read / write. + * @page: Page number. + * @bank: Bank number, if supported by EEPROM spec. * @i2c_address: I2C address of a page. Value less than 0x7f expected. Most * EEPROMs use 0x50 or 0x51. * @data: Pointer to buffer with EEPROM data of @length size. - * - * This can be used to manage pages during EEPROM dump in ethtool and pass - * required information to the driver. */ struct ethtool_module_eeprom { u32 offset; @@ -822,6 +821,8 @@ struct ethtool_rxfh_param { * @get_module_eeprom_by_page: Get a region of plug-in module EEPROM data from * specified page. Returns a negative error code or the amount of bytes * read. + * @set_module_eeprom_by_page: Write to a region of plug-in module EEPROM, + * from kernel space only. Returns a negative error code or zero. * @get_eth_phy_stats: Query some of the IEEE 802.3 PHY statistics. * @get_eth_mac_stats: Query some of the IEEE 802.3 MAC statistics. * @get_eth_ctrl_stats: Query some of the IEEE 802.3 MAC Ctrl statistics. @@ -956,6 +957,9 @@ struct ethtool_ops { int (*get_module_eeprom_by_page)(struct net_device *dev, const struct ethtool_module_eeprom *page, struct netlink_ext_ack *extack); + int (*set_module_eeprom_by_page)(struct net_device *dev, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack); void (*get_eth_phy_stats)(struct net_device *dev, struct ethtool_eth_phy_stats *phy_stats); void (*get_eth_mac_stats)(struct net_device *dev, From patchwork Mon Apr 15 12:07:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13629882 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2045.outbound.protection.outlook.com [40.107.94.45]) (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 A25576A8DE; Mon, 15 Apr 2024 12:08:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182894; cv=fail; b=qQkFGjy0BvEPmdHcp+jwj16Kpxcgdf8iEvukHrp9Ll8psUD2SEPbKX0Q9YWHQztZSHR5nxMqZix+2jcMhxkVLN3SGoMmFhP9E9FhaoeYAdJxisOR0MqAcWioLbmvH0jLojDCJP7nqgcsIyMeVFdU5elT+I63NvTaOn4Gy+N8/3s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182894; c=relaxed/simple; bh=+UpA2r/4pAWL5wRNo8wRlQcIySUmrfIftB/TL3KS+tg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eml4R5rLapzOiGeX4VpKN4O47n7w0n/XahPas1jJGgQgOyZdWtjCl6TbLlXimP/ZZkw4Sb3oTWDuBmOYGKWX+ynCfmOsHp3Y4nVkuroYYzDz705+2dLOzVKX+o/73/kr/nz/JsBrN0NzsLmqK5g63SWYDfc6u/P3L7LPTnLoYL4= 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=DKZ5uOJk; arc=fail smtp.client-ip=40.107.94.45 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="DKZ5uOJk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j0CgpfKMEwsuv4ViA/4jei1uAngZcpGaI1uVqRNV4NRymyul8gUNvhpvZuD0hITG+rFdtpWOO2BsqCASd6h8+OfXvAad4MNCdZlCS3k8mgN7n9H5jKo7Zu5wpsI2nv4siSfrcYSirwBbSmKg9jNQcgjm7auWKoi7uzhZ7heXDfLO/Z3Yw94P1SVWR5Vqnh7urW4OBmDOJGdgumCrVcgt0V8sC5kbU2aWYakxOe5mYHWB95hvSKdDgim79ZghyNSJSAQdYwDSwOA58PhINHUkm6cIPxUhrGg0cg9vjO1jDOIuUR/p1lPKipHjyhr+RIbY/0Dh/SUDfrrNnSyF7MMbBA== 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=mmuLLzSnCDGA2ZnEFUZWU0AUkSBYplvOaHdLXNkIP64=; b=ns8lanz9zHXwryM0FHf222xpQEPUALlGtfA90RbrO5OWehd1ub/Mh8HhCcgpkSg/nh6E4b4rNjDKTV5Vyw5VrSifKn7UDhZ2c9e5KWR/uSyzL43ycRBTMCGGmlGg1wyEULxHbnCGGdwZxn0oOuirFMD+Yl1jfM/9AmRF+U980e0OPUezmFHxOUradn5G/GrJvufWi+Mpr9w1T+AE4dzCCmbLhx2LG4f6wKHpP85Eh2Q1tHC+8cptz5UQz2oSQt5VnCsFANq65iEDat4/WvkoFtb9ZkUXTUGUdYoNAVheyDskuaTUIjnBxp84uvJc1+T6scRJduB4EWDxLcjb3fPG7A== 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=mmuLLzSnCDGA2ZnEFUZWU0AUkSBYplvOaHdLXNkIP64=; b=DKZ5uOJkp138iJ2nSxjFkt7AhzWGj+GD6k4bY57m2PDr9b7ofcoFPJmOoa9sI96+feDB787EnWsxkQFJ6Wg6IjzcrVHNiT6hYUZgoXh+FJVtP3KjxchGhS3uAg8PVE/LFOhGUyQB+w+u45u4I9YfZPLngEcW/KkFzuSHuEZcOl+foQH9eqz6ZNfCUd9LQXBJIG8lIQqjwZaTVFFZwL2l13GE5owj0+fxQUKxKUXLLaux3slmVjNRu7FkSoYefKOGM2WnVFkCIJlsGEvANtcblTqToypYmEApB1mADTWqhZ/MUNYEqfS8ZyVKwgV3Gb25exJmORIX44Gj/dpMNcxw7Q== Received: from BL1PR13CA0316.namprd13.prod.outlook.com (2603:10b6:208:2c1::21) by IA1PR12MB8264.namprd12.prod.outlook.com (2603:10b6:208:3f5::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Mon, 15 Apr 2024 12:08:04 +0000 Received: from BL02EPF0001A0F9.namprd03.prod.outlook.com (2603:10b6:208:2c1:cafe::3b) by BL1PR13CA0316.outlook.office365.com (2603:10b6:208:2c1::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.17 via Frontend Transport; Mon, 15 Apr 2024 12:08: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 BL02EPF0001A0F9.mail.protection.outlook.com (10.167.242.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Mon, 15 Apr 2024 12:08: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.986.41; Mon, 15 Apr 2024 05:07:48 -0700 Received: from dev-r-vrt-155.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.1258.12; Mon, 15 Apr 2024 05:07:42 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v2 02/10] mlxsw: Implement ethtool operation to write to a transceiver module EEPROM Date: Mon, 15 Apr 2024 15:07:09 +0300 Message-ID: <20240415120717.1251864-3-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240415120717.1251864-1-danieller@nvidia.com> References: <20240415120717.1251864-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A0F9:EE_|IA1PR12MB8264:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ff0cc94-769f-4c1f-52de-08dc5d44b475 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YG0jA4WUWcuqd43rhCG4jVFCwW+Lbfd8eBxjJvmgWeqVul4HsZYaSG3twvxe7W2o04NGrxljGkECIzSTozrI9RtxTMM5WMCZIeLPq0TJM0TOp+muk6THOGqv0aUVgIQH7n/equJbymB1uwsx2pY/YRE+dZ2ryzh3K3CiZbr2lINfIbCjlqOt1bP3c1C4Js8M414Vs8HBW07ySzEKWT7S/ghpDvzPwisIESPZvuMm6qtNAx358bVPljED5FDTkOsfpVFOjljPZsHF5SWXHv3Mj2CurLiM9/vJ8fydjtsGF4mSzvl/x4oUPxMXicRlrGBg9igvrvvRRCGQiVd09us2pb4q0tsoYvGI5HK80KuehCPjucqN2ZiEljP240J+AuTxJMwlm0W3yXHtyyVivIZlLirVfrlfdS7Y500OOFIRIvUxjYc7N0I1LlK9eDAK7phuoV7KfMWqlZJSI0G5mvqQTD8jsAY/H0oB2VIIwnOUbZmpZQ9l6duKxZRDuCfuCZP+JVx7h3hKJ/gAIxNVjLtZwmKsJ4zGBc9B7bt/tzYe/8Cy0oeljGd+ZJLT17YQKEBQ56xzzvzY36fXUBZkX+wdop2TdLKWbwyPovUarZxlpCY1Q38h5C9cFEYqqzWIZJlM/+ZbFiID9kKYSm9Tz2osZoUdKcEs6Xy+PjFoc4XQGfciLDFpRI6IyC14OGJrKPa+ufu0zr4zKOcF9qiPy/KC5E6URO/sU0xYN7BsQN9pynzxwxeAFqXvk+ftfLUMEv/l 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:(13230031)(82310400014)(376005)(1800799015)(7416005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2024 12:08:04.4483 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ff0cc94-769f-4c1f-52de-08dc5d44b475 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: BL02EPF0001A0F9.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8264 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel Implement the ethtool_ops::set_module_eeprom_by_page operation to allow ethtool to write to a transceiver module EEPROM, in a similar fashion to the ethtool_ops::get_module_eeprom_by_page operation. Signed-off-by: Ido Schimmel Reviewed-by: Petr Machata --- .../net/ethernet/mellanox/mlxsw/core_env.c | 57 +++++++++++++++++++ .../net/ethernet/mellanox/mlxsw/core_env.h | 6 ++ drivers/net/ethernet/mellanox/mlxsw/minimal.c | 15 +++++ .../mellanox/mlxsw/spectrum_ethtool.c | 15 +++++ 4 files changed, 93 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_env.c b/drivers/net/ethernet/mellanox/mlxsw/core_env.c index 5d02b6aef4d2..69ba9017ff62 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_env.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_env.c @@ -513,6 +513,63 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, } EXPORT_SYMBOL(mlxsw_env_get_module_eeprom_by_page); +int +mlxsw_env_set_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, + u8 slot_index, u8 module, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack) +{ + struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); + u32 bytes_written = 0; + u16 device_addr; + int err; + + if (!mlxsw_env_linecard_is_active(mlxsw_env, slot_index)) { + NL_SET_ERR_MSG_MOD(extack, + "Cannot write to EEPROM of a module on an inactive line card"); + return -EIO; + } + + err = mlxsw_env_validate_module_type(mlxsw_core, slot_index, module); + if (err) { + NL_SET_ERR_MSG_MOD(extack, "EEPROM is not equipped on port module type"); + return err; + } + + device_addr = page->offset; + + while (bytes_written < page->length) { + char mcia_pl[MLXSW_REG_MCIA_LEN]; + char eeprom_tmp[128] = {}; + u8 size; + + size = min_t(u8, page->length - bytes_written, + mlxsw_env->max_eeprom_len); + + mlxsw_reg_mcia_pack(mcia_pl, slot_index, module, page->page, + device_addr + bytes_written, size, + page->i2c_address); + mlxsw_reg_mcia_bank_number_set(mcia_pl, page->bank); + memcpy(eeprom_tmp, page->data + bytes_written, size); + mlxsw_reg_mcia_eeprom_memcpy_to(mcia_pl, eeprom_tmp); + + err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(mcia), mcia_pl); + if (err) { + NL_SET_ERR_MSG_MOD(extack, "Failed to access module's EEPROM"); + return err; + } + + err = mlxsw_env_mcia_status_process(mcia_pl, extack); + if (err) + return err; + + bytes_written += size; + } + + return 0; +} +EXPORT_SYMBOL(mlxsw_env_set_module_eeprom_by_page); + static int mlxsw_env_module_reset(struct mlxsw_core *mlxsw_core, u8 slot_index, u8 module) { diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_env.h b/drivers/net/ethernet/mellanox/mlxsw/core_env.h index a197e3ae069c..e4ff17869400 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_env.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core_env.h @@ -28,6 +28,12 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, const struct ethtool_module_eeprom *page, struct netlink_ext_ack *extack); +int +mlxsw_env_set_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, + u8 slot_index, u8 module, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack); + int mlxsw_env_reset_module(struct net_device *netdev, struct mlxsw_core *mlxsw_core, u8 slot_index, u8 module, u32 *flags); diff --git a/drivers/net/ethernet/mellanox/mlxsw/minimal.c b/drivers/net/ethernet/mellanox/mlxsw/minimal.c index f0ceb196a6ce..448263423e36 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/minimal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/minimal.c @@ -140,6 +140,20 @@ mlxsw_m_get_module_eeprom_by_page(struct net_device *netdev, page, extack); } +static int +mlxsw_m_set_module_eeprom_by_page(struct net_device *netdev, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack) +{ + struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); + struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; + + return mlxsw_env_set_module_eeprom_by_page(core, + mlxsw_m_port->slot_index, + mlxsw_m_port->module, + page, extack); +} + static int mlxsw_m_reset(struct net_device *netdev, u32 *flags) { struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); @@ -181,6 +195,7 @@ static const struct ethtool_ops mlxsw_m_port_ethtool_ops = { .get_module_info = mlxsw_m_get_module_info, .get_module_eeprom = mlxsw_m_get_module_eeprom, .get_module_eeprom_by_page = mlxsw_m_get_module_eeprom_by_page, + .set_module_eeprom_by_page = mlxsw_m_set_module_eeprom_by_page, .reset = mlxsw_m_reset, .get_module_power_mode = mlxsw_m_get_module_power_mode, .set_module_power_mode = mlxsw_m_set_module_power_mode, diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c index a755b0a901d3..c79da1411d33 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c @@ -1067,6 +1067,20 @@ mlxsw_sp_get_module_eeprom_by_page(struct net_device *dev, module, page, extack); } +static int +mlxsw_sp_set_module_eeprom_by_page(struct net_device *dev, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack) +{ + struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev); + struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; + u8 slot_index = mlxsw_sp_port->mapping.slot_index; + u8 module = mlxsw_sp_port->mapping.module; + + return mlxsw_env_set_module_eeprom_by_page(mlxsw_sp->core, slot_index, + module, page, extack); +} + static int mlxsw_sp_get_ts_info(struct net_device *netdev, struct ethtool_ts_info *info) { @@ -1256,6 +1270,7 @@ const struct ethtool_ops mlxsw_sp_port_ethtool_ops = { .get_module_info = mlxsw_sp_get_module_info, .get_module_eeprom = mlxsw_sp_get_module_eeprom, .get_module_eeprom_by_page = mlxsw_sp_get_module_eeprom_by_page, + .set_module_eeprom_by_page = mlxsw_sp_set_module_eeprom_by_page, .get_ts_info = mlxsw_sp_get_ts_info, .get_eth_phy_stats = mlxsw_sp_get_eth_phy_stats, .get_eth_mac_stats = mlxsw_sp_get_eth_mac_stats, From patchwork Mon Apr 15 12:07:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13629881 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2040.outbound.protection.outlook.com [40.107.95.40]) (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 530686996E; Mon, 15 Apr 2024 12:08:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182892; cv=fail; b=GyMXRKkwSubSclHRfSb2Wr5JYDUNIShQgBP1T5VoUx2vvDfgPKRLkgrDis6rEJftT2k2Tg88AMcQfX/PQ7FvoZjAhHGski7y8uTEAgOjktrkqTy0ohePo4M/qUj7X1VLH5h2QuZqC7mWkrKgSCe8EEgOnVhqLX2POnzQF5edUxM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182892; c=relaxed/simple; bh=XcQ2R7YiJjsh7T/WxrW0Bm6pv+6NTzK2DqXe6ntFeqs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GcRiYUpcTagTOIVp2uvlQiUsJeVXdMeM87iAXCdeIAVIMcfPSewrSOmRSMYyEvohFM1eu7BJSJvlr83jb2rXnDhwIPg55z3UYjatMRZzXaelSE+aNXVfVdzLmv6nSNywnNX8yj27k2cR3Jw8HrTtLm4seSCg9NBfo/AK2wRf7oA= 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=SogjLIUv; arc=fail smtp.client-ip=40.107.95.40 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="SogjLIUv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TeeW8CyS2rR6nJX2jpOCNVaV/2KY1B8fKtAYP5Ua9YHq0sHoUkD4Yu6gGifki8xA6McjshcAgyw4ksrM/ROrQUGnG1AgSh3+nC8BMYfniRKS7iXd3nOI56KM6+iBj3fLHkCswE/a/MBkJgjmRXyGV6hLZrx+arnFQZWZTsliBCz58U1HHEVEq3fosyKBNc6TmCZCd+ioxdxmbutUOm+2HUJo7/+Ipf66PVlo2+kSgotuiUdg0jw4xw831wH+lG6ZTQyyzhls0iu4VALjsh6sKfWCmFUq/u2UYZeekET2KivsG+6kc9QiqRdhN3ynaCF2il22RSd00GsRUdOS5EfmNw== 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=RlBLox3pqizc2S4V5n61qGSPgpILKHXqhYrZ6UbesPE=; b=Eigz9/2oLbOBvp6nqZV3U9pNzqYavtTZ57app64dW2x9zo5LEPlGMBg/yigD4hPaxdlw24Z1yXhT3JoLvItTVJlKB/ZmFGBFyrigXqU3aKFGvdWBSfS7VwQunAEWyaIdGYZtDTdc9Tv9ggDkHVQzjBS3LXSrxZ3xT7BLwTcbDhORKTzyAf98MmmsAttE7k7Oj+SN2vbIdh0XaGrfZMKt0gT92ChHu1EqZclqf5DQIRcg0tleyuKmPzFDWs4uaVpTDKMDXxle12Ajb3ijcbA77QG176n8EoEa/WreFAb4OnerLLaMYipZ/3NAsfMfLcm+rhTkloDNLPLwA3Gatf8V2g== 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=RlBLox3pqizc2S4V5n61qGSPgpILKHXqhYrZ6UbesPE=; b=SogjLIUv3MoHg8GSzcOHpcXhREl7jSh6DbmFzJBlP+uJxLHeFdCS202mJB8/Wh3bAuIb7TkZkDwaoaxtULfxgs4wh316gYhmPUAKB/qu4J38mPZXbGcvL/mEJYc3prvgqrPNbhYacSVoq0wyzMZAvxxr3b8QN7iLjusPzF9kAEFjBY50eMz413HSo0fD9zx7khhJ5ad1PeDgn+TuXvjB4fXk/Ql0UpKUlmNvv/mTI6dxSGMaudA47RIakQr4WjSITdtpjE5Z4Scf9QSO7hJXlYPDkB5yFE6EOh3OmLAFyhHHGGIV9YNZ0mHMZAwxMNqtsX1f1sDRJful9xonkxzCow== Received: from CH0PR03CA0090.namprd03.prod.outlook.com (2603:10b6:610:cc::35) by IA1PR12MB8224.namprd12.prod.outlook.com (2603:10b6:208:3f9::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Mon, 15 Apr 2024 12:08:07 +0000 Received: from CY4PEPF0000EE3D.namprd03.prod.outlook.com (2603:10b6:610:cc:cafe::8) by CH0PR03CA0090.outlook.office365.com (2603:10b6:610:cc::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.31 via Frontend Transport; Mon, 15 Apr 2024 12:08:07 +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 CY4PEPF0000EE3D.mail.protection.outlook.com (10.167.242.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Mon, 15 Apr 2024 12:08:06 +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.986.41; Mon, 15 Apr 2024 05:07:54 -0700 Received: from dev-r-vrt-155.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.1258.12; Mon, 15 Apr 2024 05:07:48 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v2 03/10] ethtool: Add an interface for flashing transceiver modules' firmware Date: Mon, 15 Apr 2024 15:07:10 +0300 Message-ID: <20240415120717.1251864-4-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240415120717.1251864-1-danieller@nvidia.com> References: <20240415120717.1251864-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3D:EE_|IA1PR12MB8224:EE_ X-MS-Office365-Filtering-Correlation-Id: 995b31a2-29de-40e5-be54-08dc5d44b5eb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s+vpRGdynbnYh5t/keefieQd9FfnfYCTJ0dpuhrVfA7ATL/bOwolUnAQ97B7kiybqVLoEnHYXDhqncZGRmd24MEQt4bMrd1Qnwo6H9xmfEYNlQwySXOajWs/YKHOQDBK9uigijuMV6ufdLUFzx8q+ThOqqL0grdrB7J4HUI/lxb4IGpwdMq/o7snVllb7gGMw6C2rXxGbvtfPR5PsBJGqBB1rhDL1HTMRzO4ZIVqxtzKWQrdTvyV4RIVK5vgC0jVqeqlh0ArBAHmbHz5aciQJ+mmyDnP3uduPs5+UzY3VGusQwELCQ5U6ra5hteQeO65QqoiaeHi3aPvHdIxA56rq4jAvXhsi4QOp3oxllUiKl3DER8Gx3oXmnTYP+SafvdQTvfWHVynd0BRitbK/znRvNPKP10EiEvuJLNYy7KLBVOCykoFDvN1OlDz8ZsdfwUCybBEMC3pjrNWAqdcQh1hQPQezD3vYXgVsNpMjoyG6NbFQwkhoUV0MutS9Qiu5+wm/HdFts+DmUcOtpYx4lcH092/HA4w7evXzHiF1sCf2jazYEM5Ii383ey3lC8hyaN8kKN2IOhL3TimYaskUCi37ZJG7ltQdK/dD0FiR2tg3kaAYQVB9M1427Pw+leobICx6PQe6Ik9V4QGYgdoWa7G4vTw3JErzFYONGJz0DZAhjYPJ9CAFsybUo0BuG4eFl20oGkRNbyHhUse7srhTltQ2sfrhC5vuzu9MbyFHmS1jK77Ca9v3Fg/Gb9cm4qkQGg2 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:(13230031)(82310400014)(376005)(1800799015)(7416005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2024 12:08:06.9646 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 995b31a2-29de-40e5-be54-08dc5d44b5eb 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: CY4PEPF0000EE3D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8224 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 --- Documentation/netlink/specs/ethtool.yaml | 62 ++++++++++++++++++++ Documentation/networking/ethtool-netlink.rst | 62 ++++++++++++++++++++ include/uapi/linux/ethtool.h | 18 ++++++ include/uapi/linux/ethtool_netlink.h | 20 +++++++ 4 files changed, 162 insertions(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index 87ae7b397984..718073f4fb3f 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: - @@ -963,6 +967,39 @@ 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: module-fw-flash-ntf + attributes: + - + name: header + type: nest + nested-attributes: header + - + name: status + type: u32 + enum: module-fw-flash-status + - + name: status-msg + type: string + - + name: done + type: u64 + - + name: total + type: u64 operations: enum-model: directional @@ -1715,3 +1752,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-ntf + + event: + attributes: + - header + - status + - status-msg + - done + - total diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index 4e63d3708ed9..76ec2ac0d013 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -235,6 +235,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: @@ -281,6 +282,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 @@ -2020,6 +2022,65 @@ 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 is composed from 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. + +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`` | u64 | progress | + +---------------------------------------------------+--------+----------------+ + | ``ETHTOOL_A_MODULE_FW_FLASH_TOTAL`` | u64 | 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 =================== @@ -2126,4 +2187,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 95c2f09f0d0a..332df9f36062 100644 --- a/include/uapi/linux/ethtool.h +++ b/include/uapi/linux/ethtool.h @@ -822,6 +822,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 b4f0d233d048..c98c635c532f 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, @@ -994,6 +996,24 @@ 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_PAD, + ETHTOOL_A_MODULE_FW_FLASH_STATUS, /* u8 */ + ETHTOOL_A_MODULE_FW_FLASH_STATUS_MSG, /* string */ + ETHTOOL_A_MODULE_FW_FLASH_DONE, /* u64 */ + ETHTOOL_A_MODULE_FW_FLASH_TOTAL, /* u64 */ + + /* 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 From patchwork Mon Apr 15 12:07:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13629883 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2059.outbound.protection.outlook.com [40.107.236.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 965CF69946; Mon, 15 Apr 2024 12:08:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182901; cv=fail; b=TGUqYxCflaegpKqwnOpPw1/N7vfiM+i8Jv0safVa8gzyGJ7P8bIXvs6d/rwmIIFxqNqroHOQ9YIrYD3eCrJ29c42e4TWGi44O/oqaHBFkJbHfzTuZjv8hDdbNQk+wPNJcgWQ6Im/uAHg4KeYFQAy/wFwd4GoJRi35EEPc8tzw4A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182901; c=relaxed/simple; bh=OFdknu9ifl1dVUn93KjLhSo9144ESrNZYUFRA3j7NGY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cgAj63lB1NfynmXvcRBbtsozw82SwYEeJb3T4mGq52uPy928MOFXMiIs8FSl/IEH9nCFIbk1pSV0+JTkviQW7Axyxa93rbSfWjGbqvuwCxk4KT5d7lLOmoQ7UBIvGoEkxlrI1AbHyFA9eqCectE1WH+vSQRNDmvzC+/6XOXOLvI= 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=VI3lqkgz; arc=fail smtp.client-ip=40.107.236.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="VI3lqkgz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kJZN0CNZ1VcfiDo4CwpXCZ95QEOhkBM8/AqHVloinFuPG1qvao0OWR+3+Lk+U4rBjLFvb073mWMlOK/nd5yB4CaYSlfl/Q/SMsss7ppWnQHRfsWp54AJvYTsKGCv/BXRIwpLUfiKCwhrea994Tbghx0zqJs5XFDH0r+3R86YAFOgtVewAMHK3xU4b4Kt9mqCy0FaSLKtS6trXTWh2FesC9ZmJ7H3nYn+XKGoR2moXU4MNQX0dq6T3dvLRqAYqNooW2gS/EHZltAqiIPgpKIBISmK4QF7kVgLIENiX922+fUom0SVhIkxN2/sieEXDMybOa3FbWd3vioUOsrvqrGNsg== 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=C6Kbu2o11318dCt1qo3ckSYzDcjsotrcsFd1iZusCBM=; b=USSxgPWSJot3VkHwWs+yi8GTTqM2XA3YUn64J+QbOQ6s2+M5z/hbX+LjZo23ouWhOCpl6079SP7A4UhGyoJbzoY7SQeEeCSAw0Ch56kPmHwNtXe5j6oZdQ+IAwuWOniSjKZ4qFDD3elobKMoyobO41jeYS/XNR9qbWlkqkcSMfqa0XgUxI1axjyxBJaDicDywRtzdDty77a1khMj5SCvIBEEKERyjfs7FYXS05EyrIci5tIByi94AFTr1AF6K3LZ4xbJN258ubsvuAIVOw3d9K69t/4gYiHa2qHsr2WP187fCqrbIBxVajx26qhUTn7N4S9IyJ7mobJptKzhZZOweA== 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=C6Kbu2o11318dCt1qo3ckSYzDcjsotrcsFd1iZusCBM=; b=VI3lqkgzO07fODzlSDeDMP1MF/xWPjOfNO0WboWA0B1GiGWkcqa4Yy8tNa4Jlgwa79wQF8EeK//dpLHaK+tBUIRd4fghBF10xt6XxcDkrjT1cCdzmgugCr24/K1rj06tcY9uBsT5t4jcwQj/cOCmKbuoruASSSKPCMu8t8caKHSap9/r4U0gbyYHduEOm9Am5y5NZYjxOrBMyAa38rykAVRFBMFFaUaEAMmEvLczLw+wQJ2BOFU/EudGLbS6L8j+VrIqKVEHx0laNQUo9UbtLE1eQxXDSsoIsct90yyC+AD11isMcw6nz0cGRSNsrDMYNOSliFuJmWxOYPuBKr+49Q== Received: from MN2PR07CA0019.namprd07.prod.outlook.com (2603:10b6:208:1a0::29) by PH7PR12MB7211.namprd12.prod.outlook.com (2603:10b6:510:206::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Mon, 15 Apr 2024 12:08:16 +0000 Received: from BL02EPF0001A0FF.namprd03.prod.outlook.com (2603:10b6:208:1a0:cafe::78) by MN2PR07CA0019.outlook.office365.com (2603:10b6:208:1a0::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.34 via Frontend Transport; Mon, 15 Apr 2024 12:08:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF0001A0FF.mail.protection.outlook.com (10.167.242.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Mon, 15 Apr 2024 12:08:15 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 15 Apr 2024 05:08:00 -0700 Received: from dev-r-vrt-155.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.1258.12; Mon, 15 Apr 2024 05:07:54 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v2 04/10] ethtool: Add flashing transceiver modules' firmware notifications ability Date: Mon, 15 Apr 2024 15:07:11 +0300 Message-ID: <20240415120717.1251864-5-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240415120717.1251864-1-danieller@nvidia.com> References: <20240415120717.1251864-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A0FF:EE_|PH7PR12MB7211:EE_ X-MS-Office365-Filtering-Correlation-Id: c84b3563-3a5a-4be3-09d4-08dc5d44baf6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yjUAiAz1TEW0HniDMLIRRSptgL0aUc+07GlembrOZw3+0GtMyFbQW1Ztl19T4Pjcg5KDxrRncDzOA3F8iuuSDtK9dCiO7VL/kEcXodYA7OscnmhQj8DUBjdKP+IcX7Ug80A4ofvxJaRumjVK5NqqUhKluVMpVQwlpy/NYn8/F3252e/qD3Uc5SWCdfCzYnZoKUNCp9bDwBIUtbdV4cFDMQdA7kwne7J3YArg/F+TmINCXBJHixdSh85njyH4USj0IgoIoBiyrNOzG1OdETNSkXBao7uPu2ovtEyZmH+An50xYTfl54LIEbHnOyTC1yqifMKOf/fvmAFsvDApSHMwBxcNDQXY8xJPEfKqDqRyVNzmF8prF7xRBVcTiLHrAlQ/153mcd5/JVw5BJ8NIbbhRIrUelEynOy6zFuqrjqiCbu31ptk6PaDajFQhrGHlYB4i7bMRQtPl4LKkobczdLhWbCAsnvbiOiDJmr/WYwxVRmS6G+0bQDAC3bkyw8OqmWH54fJt4Uo/4NG4oclRP8Qz7TliOUsD6c19/jVVC4KXgbpWF66csBA9Tzc+hOWSYMmh89ZxjVhNf/NnI+L4Z3v45Y5ShABgwdOz5d+7bdhplWIfAGFYWQtYY8rmC6rdDvAnVQQfZeav9prnGXcJhM8wu4IiMKPDJ28LSSuC2wrWWepTSa91zcuYG6c7jyk3t8w1kjwkNdrfxdeIilXzQoojUNTsIL8JgVs8z8sg95hl7vwt/WSmc4pIJ2mYKweBKVq 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:(13230031)(36860700004)(7416005)(82310400014)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2024 12:08:15.3426 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c84b3563-3a5a-4be3-09d4-08dc5d44baf6 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: BL02EPF0001A0FF.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7211 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 --- Notes: v2: * Increase err_msg length. net/ethtool/module.c | 83 +++++++++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 10 +++++ 2 files changed, 93 insertions(+) create mode 100644 net/ethtool/module_fw.h diff --git a/net/ethtool/module.c b/net/ethtool/module.c index ceb575efc290..1c659bd85160 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,85 @@ 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 void +ethnl_module_fw_flash_ntf(struct net_device *dev, + enum ethtool_module_fw_flash_status status, + const char *status_msg, u64 done, u64 total) +{ + struct sk_buff *skb; + void *hdr; + int ret; + + skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); + if (!skb) + return; + + hdr = ethnl_bcastmsg_put(skb, 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_u8(skb, ETHTOOL_A_MODULE_FW_FLASH_STATUS, status)) + goto err_skb; + + if (status_msg && + nla_put_string(skb, ETHTOOL_A_MODULE_FW_FLASH_STATUS_MSG, + status_msg)) + goto err_skb; + + if (nla_put_u64_64bit(skb, ETHTOOL_A_MODULE_FW_FLASH_DONE, done, + ETHTOOL_A_MODULE_FW_FLASH_PAD)) + goto err_skb; + + if (nla_put_u64_64bit(skb, ETHTOOL_A_MODULE_FW_FLASH_TOTAL, + total, ETHTOOL_A_MODULE_FW_FLASH_PAD)) + goto err_skb; + + genlmsg_end(skb, hdr); + ethnl_multicast(skb, dev); + return; + +err_skb: + nlmsg_free(skb); +} + +void ethnl_module_fw_flash_ntf_err(struct net_device *dev, + char *err_msg, char *sub_err_msg) +{ + char status_msg[120]; + + if (sub_err_msg) + sprintf(status_msg, "%s, %s.", err_msg, sub_err_msg); + else + sprintf(status_msg, "%s.", err_msg); + + ethnl_module_fw_flash_ntf(dev, ETHTOOL_MODULE_FW_FLASH_STATUS_ERROR, + status_msg, 0, 0); +} + +void ethnl_module_fw_flash_ntf_start(struct net_device *dev) +{ + ethnl_module_fw_flash_ntf(dev, ETHTOOL_MODULE_FW_FLASH_STATUS_STARTED, + NULL, 0, 0); +} + +void ethnl_module_fw_flash_ntf_complete(struct net_device *dev) +{ + ethnl_module_fw_flash_ntf(dev, ETHTOOL_MODULE_FW_FLASH_STATUS_COMPLETED, + NULL, 0, 0); +} + +void ethnl_module_fw_flash_ntf_in_progress(struct net_device *dev, u64 done, + u64 total) +{ + ethnl_module_fw_flash_ntf(dev, + ETHTOOL_MODULE_FW_FLASH_STATUS_IN_PROGRESS, + NULL, done, total); +} diff --git a/net/ethtool/module_fw.h b/net/ethtool/module_fw.h new file mode 100644 index 000000000000..e40eae442741 --- /dev/null +++ b/net/ethtool/module_fw.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include + +void ethnl_module_fw_flash_ntf_err(struct net_device *dev, + char *err_msg, char *sub_err_msg); +void ethnl_module_fw_flash_ntf_start(struct net_device *dev); +void ethnl_module_fw_flash_ntf_complete(struct net_device *dev); +void ethnl_module_fw_flash_ntf_in_progress(struct net_device *dev, u64 done, + u64 total); From patchwork Mon Apr 15 12:07:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13629885 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2052.outbound.protection.outlook.com [40.107.212.52]) (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 2C5F76997F; Mon, 15 Apr 2024 12:08:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182914; cv=fail; b=ZP53y4VT+T+CQakLg8AEsEThFKjRyjt6Ow43FHr5h+Hr0xdr0sccwkrKWrYaD8QBL665M229jqHqmfxt0Rr3wGKPYAMvJWztLdQZD5jT4WlPwXfGoqz7s7vezhVcA2k/jFvSUTELs5DNyyGlA7PK39ikhCcGze1vM1ZOBVzHPms= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182914; c=relaxed/simple; bh=QyEJTv+ju1WUuRomf/6VJUg5R13KnCo2VxHBZutDlq4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mesLSqVN7QtAcR2sIUxKy5cXtptZODRLDJsaavKqA0E2jfwz8LLoKYfERMp/vv6b+PLemryE0mSh71bg9f9NHXtbQdBP7ZXsVdw+j6+vSfqICTUgf/cpBtKSd0cYQy7fXsHPgKXA4XoCiPk3GZsGP5Rj2qkgWTBe4ios0qA899M= 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=A0wvO9L9; arc=fail smtp.client-ip=40.107.212.52 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="A0wvO9L9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ihi4EgQM1d2ytX2rSU6ARbjNYQZhpMVVwVs5R3tHZ4gD/+4KdigWNbwgv+mH/TKaBqpnSeAU78v3M+rKtVCBwQQbArIBtFNtkb2DuWQuMbVWa1Ds/Q6X+thfY/FCUXibR95/RfIZHm3RZXNMMU1qELyLzpUwRf+I49qH5EULqg5cEBsPNu1DWeWArPLAjJqms7rEM2LNbTVRKYe+o58KaWOo1BmFPJL7pX+OmbUVAS7umgR9R8gElsUny1Ndg3KVQQ0cp//SVhYcPXiwzLnWyA7y2Mpyg1IO271o2c2w/9BKZ2Qr0YDNb4EUKWjkT3TS1N6sS1ZIImyrnPCitlDgEw== 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=WmEPOJp/OF4fh6S7KCaOH+lyLGhpUOti9wiz1S7s9Nc=; b=D6hGpA9Nn9CvjEAgrcVqPXVcYTlMn40ThS6hEAJvK9/Z2LQDw9KVhYQnkQvY/XRMt0dti81PBzqFyyF+9xUvcb8SoiRYwDo8yD4D2GmIzHKh25fw0JiKCmYymKDO24EF0D1/Tbnf4TFpLctJBfclDhYH4lK5dsq16bqkln+Tte3VDvKvMeyibmmgF8s/VoigxiI5g7tPZbnhI0r2fG3QAGeQIst3GURAxMv54FRFqu4xSuBa1Y1LePidf8z8lr48GUHl8L89FcNxH7Vb3nIM/UCMXDjBbhKWOMt9p/Y9vACqW6xBSnZwyUVoTauIK8PbQFaJqmNGbWN0BoS245orqg== 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=WmEPOJp/OF4fh6S7KCaOH+lyLGhpUOti9wiz1S7s9Nc=; b=A0wvO9L93iyrXjFInnRI1meS93LFAzXEqGMN5EgC1uBmq8ouOmrn8LJPR16fMKVFxdHX6wcBdpFig4515z8KQKLfECWK3OdO08NmsWmnt6kzB+k1m/rxJWTP4eeoUX7SJhBtbX9rSMn8197Y6nQgf+B3+RwJ2w4R00exIRDqfEGkMa90r/Sflm4cz0Kmw+//4ubKqySAAs8auS41k2GO+EjFIWDsQZ4nkh+jr8C6rL6NDr8qyYnzzkhTTofSXdSBCAUE0G2TLCRPs/DlZ2dZ2tpa9DDkfmrgyRCsZ6XHS4ZsVMrzoaJuoxTB4XK7xfNS++TdHSh7/DttmHG2gPk1Qw== Received: from BL0PR02CA0082.namprd02.prod.outlook.com (2603:10b6:208:51::23) by IA1PR12MB7637.namprd12.prod.outlook.com (2603:10b6:208:427::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Mon, 15 Apr 2024 12:08:24 +0000 Received: from BL02EPF0001A100.namprd03.prod.outlook.com (2603:10b6:208:51:cafe::e0) by BL0PR02CA0082.outlook.office365.com (2603:10b6:208:51::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.33 via Frontend Transport; Mon, 15 Apr 2024 12:08:24 +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 BL02EPF0001A100.mail.protection.outlook.com (10.167.242.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Mon, 15 Apr 2024 12:08:23 +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.986.41; Mon, 15 Apr 2024 05:08:06 -0700 Received: from dev-r-vrt-155.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.1258.12; Mon, 15 Apr 2024 05:08:00 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v2 05/10] include: netdevice: Add module firmware flashing in progress flag to net_device Date: Mon, 15 Apr 2024 15:07:12 +0300 Message-ID: <20240415120717.1251864-6-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240415120717.1251864-1-danieller@nvidia.com> References: <20240415120717.1251864-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A100:EE_|IA1PR12MB7637:EE_ X-MS-Office365-Filtering-Correlation-Id: fad5ea08-45b0-43ce-18c6-08dc5d44c00d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qtHDKfYhoqIw0v9+regJDu+tQVycJM4q/g2U9f4BcnfrWVU342bZLNWPo0+4sbVOkf2QNTNzQU/uA6/kt/bTB+PFgSLndS9AW/MolDKsvmjGY6DlDTxawnk7tVxuC1XsvGgOervaANRu0vZckh5NGXus0Tz7kGpNMSxFTOe+pPezvOUw3yYyYzphHaMYPJSEWtC7XQEvQqyKpJKOo2xOoUFtR5wyp590sC8CuxD8yUeEHI0qauq3VGgAKu4rVV420M7YZ8gGPhNXpxr9W8Ks0bDkVhHmzNhmrproI9f0Hh1VC+CZcxxGz5z9byKQ1/8Ekab0a6UeumIeDekujbgGphXVGIAOgMwz1E/WVum9NgbZZAVjnFqSS/pE+Pq68w8p2WDWeO4IBvY9mvm4Pf/DDpgPMb65V2H3YhIP5Llixt6Z5kT+ERnsv1ES9hcOetqmGeWGN5qU/lvhg4rDF32jfQdFfJdMcafKXwqePXVayXYLpn6NGhx10gSkG1RaXl+0f33mBko2aolxqDBtz18VeAFCaKz9b8N7c/cErE869Uc2J+9F6v6vZCyejOfMSGizjmwzh/2qc/TKlrDnlbDUTmEWr/2va5mlKBm+FioCIyYArRUC0RX6yI+a2j/uIskaV5uX9LeG2RQAcwDlIpTGJPTYq3InXDW8bPHDm0G69qOqEFXRulw8HsMac5kEXx2E1HJ3iaPBFucRVrpDCVmnT2O3TCK2h+im50pKmS265lNJS3CdRimLjiU4ahr1Wb5R 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:(13230031)(36860700004)(376005)(82310400014)(7416005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2024 12:08:23.8979 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fad5ea08-45b0-43ce-18c6-08dc5d44c00d 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: BL02EPF0001A100.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7637 X-Patchwork-Delegate: kuba@kernel.org Some operations cannot be performed during the firmware flashing process and will be vetoed later in the patchset. For example, flashing firmware on a device which is already in a flashing process should be forbidden. 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. Signed-off-by: Danielle Ratson Reviewed-by: Petr Machata --- include/linux/netdevice.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index d45f330d083d..5dfcacff1db0 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1989,6 +1989,8 @@ enum netdev_reg_state { * * @threaded: napi threaded mode is enabled * + * @module_fw_flash_in_progress: Module firmware flashing is in progress. + * * @net_notifier_list: List of per-net netdev notifier block * that follow this device when it is moved * to another network namespace. @@ -2372,7 +2374,7 @@ struct net_device { bool proto_down; unsigned wol_enabled:1; unsigned threaded:1; - + unsigned module_fw_flash_in_progress:1; struct list_head net_notifier_list; #if IS_ENABLED(CONFIG_MACSEC) From patchwork Mon Apr 15 12:07:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13629884 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2046.outbound.protection.outlook.com [40.107.244.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 A35C66BB5D; Mon, 15 Apr 2024 12:08:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182913; cv=fail; b=J1ThR1EgZCgDG6ZTA1f7we40faQAwGKkwI+XMOlm9/O2Gta9uF3mP5ogC0OPFFsXutsaGAFtRquTLekuCig4f+eufY7GhMbBo3cH5u5HulMwvRUHfGs2E1TqWKoEpNPicaUesONPSJ328vnJOSmNzl7uuKmco6YZPELxOEKNTgE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182913; c=relaxed/simple; bh=SdR8AK9p5eXkXVsxuQJGJMTlfnSMm8NrhQSC3qadvTo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=heNQ7U11I0e5i/qdspdpzPV508zqcxSbobJ6e+nIgwofA72goaaojgvmx3SPz3sJ9xGl1wSpeWFk9Zm7G5o50q1LTGhzMo8EJavkMUvjjVXH1OWJHOiDIBkwfzt+ox9ZafyRtpk+m3T5SQ/j6CDY/KJbBpXYXOsO3YMOAthQDSE= 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=P+tmOm36; arc=fail smtp.client-ip=40.107.244.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="P+tmOm36" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VbQm4myg36j3g4nXcZfDCvP5bn0m9sU6SWkk2YqDAB7XrHTEcPoRtkxJs3mgDRhL9tWS5oHD6inv0Je2MlJFP5po1LcWPE7W5klK0oiJXhPen+jpC8VXk7VZAZsVvcRONZk3mBzygvKNpiJyZp17Bh/62PVUPGlDwoFOcWvPyjhdGyFaLyC2JnI7B5i68K555EbrwCaa1/G/u+Ll3RXGnFFdzeI+AviNrUjs9S4pYkxWvA4hhdlfs4raXnuHCq5DCMMYhpu8yzyRemY506enYs6W8nQs9iElBN9jGzq0GXmdhrWsAIAypWV9zi7G+FMiu72ZerpDCTA8tUQ/oe8gQA== 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=6V1UnlOS3EMUCV6lMUtqtDUSLw94CQZRNztlwUtCjPU=; b=fjeLHpaZbIglBuvmTvXjWDJJQDQ/vx6Pa+FJ4T014QaXavN0UE2dmrBmgpnSCVG/yI/4E0H8ORBVqHojBquXLL/dNsGJRs71xOmjonzktfVS3G30W9K3NssedmOCngYvJR13Q197idr5ZWWqIM1QknvGjxViHPKRrOvO2H/9ozQpti85hnjSf03vkrMv/H9zdbrMRjbgC/eW8zj2nQDsVlG7hcGKHL5BG7Vm6zXh+GecNCg7QayxofwBFRzYfpsrVrwalPcfbwhYZfVek1mAw2MOWMUUjI/X4te3nSEFHXVBiBqk0nntmcR1ttBwW1VxVo/TIV8IJ7eDTnAPQ+fxhA== 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=6V1UnlOS3EMUCV6lMUtqtDUSLw94CQZRNztlwUtCjPU=; b=P+tmOm36pcNKkAxYklHtqwDgAj8LYYN1RyZjA0SHAxxUOaVaBWF5dpdWp784FV5+4XEFwI8LUBcWb/JHql8gah4PA5G9XH9rwqriaoGzb6aztEUo4W8t9wKlm02dBB+etlOdahh01ecomRaEsuFxu/Hw8SoGO6EBlGfmb5jbBxMO7kGC3kLzeQ9i6cPGTno9u2dcv1E6Yz70XU9jNO6wFvSBOuaJiDsUN99vgFlLiSzUukgHl9diHG5orNufMfdmHRPcUxHC/oT9JES5z9yXP8Qed67C4oeqFXOr1bkbZzntQeW+AP/XoXnnLWKHO5ogUk96H1bd3sVrHZvPAB1YbA== Received: from CY5P221CA0006.NAMP221.PROD.OUTLOOK.COM (2603:10b6:930:b::11) by PH7PR12MB6907.namprd12.prod.outlook.com (2603:10b6:510:1b9::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Mon, 15 Apr 2024 12:08:27 +0000 Received: from CY4PEPF0000EE3A.namprd03.prod.outlook.com (2603:10b6:930:b:cafe::52) by CY5P221CA0006.outlook.office365.com (2603:10b6:930:b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.33 via Frontend Transport; Mon, 15 Apr 2024 12:08:27 +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 CY4PEPF0000EE3A.mail.protection.outlook.com (10.167.242.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Mon, 15 Apr 2024 12:08:27 +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.986.41; Mon, 15 Apr 2024 05:08:12 -0700 Received: from dev-r-vrt-155.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.1258.12; Mon, 15 Apr 2024 05:08:06 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v2 06/10] net: sfp: Add more extended compliance codes Date: Mon, 15 Apr 2024 15:07:13 +0300 Message-ID: <20240415120717.1251864-7-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240415120717.1251864-1-danieller@nvidia.com> References: <20240415120717.1251864-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3A:EE_|PH7PR12MB6907:EE_ X-MS-Office365-Filtering-Correlation-Id: 24653a33-ac63-423e-15f9-08dc5d44c1e8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uW4PFv1DJn1seyzuMwugsi+gdOSfvcJe0t+rHE1vGD2GzyZHxgr+Ojx/2eBkT1q0xwdPO0I4Z+kbW1JeJl5ZH8Xv6LnIl7nrtPlnkYAN6kzVtavpXT7fBAaVW1M//64AnhN4hd03OlqY7npo230I1hky13cD6Z7REC400OvaiPfxgROmxhlSAMxVyYoxUavSkk+g0jgqWks4TsPaDmKzOVAaAxidU0zDbtmPfCm7gxKu0w4LSAajjh4cq+SAjnmiFlU+DYzXHg8rfFkc13caBNmViM8xYYHz6Yh/HLRdBBUVa2ND1BHn0dhS9ezzQWGHnoXv/vl6PT4EtKtGiSuriLAcwg9t516y/b3imJgfLbPnIoA+loXTxr25VVq/tEvuAlp/QQJo5f02vL3A/y7N3RKwReCrCYP4rpLZdv9nSVgwzj0MWgN3ol+09nxu0vNzqK0rXozKqejOrLxkDVf5VFho7w6SXK6DXnZVZ/oKp291kVeuAz0C6E+88J4lDYSrU3B2+BIkZyWjFTM3WidJKoQPki8mUz4C/kS3WDooynemqzLNZnoBjzKRTA8vvQLAEFwmyfqN6cmtuvdtX2nUf4TBe80zT8ZziLqXDw1bRJ23pWkVbDvuuZ1/nuVD4jMl1gzW5FTH8KRw+JX/sVlGKFaVmdaUKpSY2tOJnGluDlFjpc2KElUa7+ti+bHZW3N0TJ2dGaruW6IJAuETbwHsCMd6+aPiCybRmg/GTJhlk7LF9Icb3xxQmDEycREbTG8/ 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:(13230031)(376005)(36860700004)(7416005)(82310400014)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2024 12:08:27.0577 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 24653a33-ac63-423e-15f9-08dc5d44c1e8 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: CY4PEPF0000EE3A.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6907 X-Patchwork-Delegate: kuba@kernel.org SFF-8024 is used to define various constants re-used in several SFF SFP-related specifications. Add SFF-8024 extended compliance code definitions for CMIS compliant modules and use them in the next patch to determine the firmware flashing work. Signed-off-by: Danielle Ratson Reviewed-by: Petr Machata Reviewed-by: Russell King (Oracle) --- include/linux/sfp.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/sfp.h b/include/linux/sfp.h index 55c0ab17c9e2..46c145fa855d 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 Mon Apr 15 12:07:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13629887 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2075.outbound.protection.outlook.com [40.107.237.75]) (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 956A36BFBF; Mon, 15 Apr 2024 12:08:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182926; cv=fail; b=DdtHcYXHz4XIMqTF9dC7SYam6l6S7VMtaaqqiZ5SnVqbYdP1RoRHJkpRD6KUfnvxde3wYCJSy54/Cl3kXm3ywZbEHqZeLpc+eK6cTjXFOA/YWnO2IYRHAfyHsLJuRsq/BJMXXULOzG+ziT2w8qwJ0MwhBLlJgm2F0S7EyLqWGKU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182926; c=relaxed/simple; bh=qEhTyyZBWrLNSplMk7PHzjoOEgeMwL0j3wxqKYtdaIQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eLTq7S0u99fEgQoRScwrMHxgTyNVkDXp5DcpyhyybSMXiB08BmvJv6GnT76JP3irp/egY0tCfBD5OdWdTZHOhpIjH2qzzWu/Y/Dk2vL1P32gvDPxs8GJ+hAVdj5PNGFAyTGeHB/38LS822o4b1AKEtNomzmCBqAiR+9QkgsjCr0= 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=qUzJM9Lf; arc=fail smtp.client-ip=40.107.237.75 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="qUzJM9Lf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dFT40e1j1hnXJHhfbLt6NPaCpkqwbfJbgrBKdfkrDCqGq94Dv0bqxrfqA0jt6Ujr6D5aHXsU6by1seyo46wtZyACsqNdtU2BK8DQVq5Q0KYnJSZcpr8AQijfzwcvBB7DNBBPmuSHi5/dnDYnDZICvH5cDkCF7/rZ9+bNcVeRWbfMwpVqAa0Q920xCbCFARdYF5yT/ZezGOC78g0xBCWMgdGvwewA3RqdS116YsGPmI8+0+DP1HfJRkFOqAp9PtTyfK+11xUnDlFELfuNlD++MOr2K6tGaKebtcsdQPO1YTFUVz5OKNYeXan1PWuyd/5mt7TzWu0GLkCMw8mQWku7XQ== 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=l6DkmUvmYi49wa1jhs2lwoq0IkM/ZALPmp8581Yp0Xw=; b=cIxdWsYqDpwfdy5c0v/k+xC11fmpd6SpN+zV3ssfNv6IWZMgf6l9u5v54JOql62Nypnqo4yyoLgH5zbH32IBAIYUJ9k1Jw7DWuUDIMt9YqYrJOZ9qmlXix1qMibNbm8IV4l5VqtVat0q2YMRJRiCAqOjJF0cr5hx3EfrNHfJacY92PNCtFqZ9c5MWwsywA1SRf62X2Ph1Ai+9JE7hQhuvtFHIVaud1nsF7InX3jDUl8IYSMCN7U1p7bNZzssYc/Njo9AOkUGX99ewWeWoGKgr0StEk+Ki1RRgK+MhIhSc7VgmEnXxfOm5FoPEnJ8bE4MW39Ol3hK10++xD6fcLpyUA== 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=l6DkmUvmYi49wa1jhs2lwoq0IkM/ZALPmp8581Yp0Xw=; b=qUzJM9LfxOCt+DTVNnxSknivrVX49toXguE8NPdPSKJggbpqRGXtJq7TP6M6w3UIEENeZqpYzXg/SVZu1O9Ir8AhUeY0rNMcWHrbwcjBeg36rffO4f3ZX6BuyX1BYXQWQrLubczUHgHt93Yf3t4MeGm4IVBY3HuGku9YQDBaqMlFUBabiUn6xSttyg6xBHRJeL0UER7Mc6aixy1WvFgsONfwj8Q3l+bNQnxT2dylQ/LAR5NhrVmG8KBgULQjmEax0oTVhL0yQMF0VSiPtrw2wJEgCE75RucVlsjaXajTjKBlYbOOy4fAnbpQrU/z3dL7ukwWHPROYuYoZsWNT6xV7Q== Received: from BL1PR13CA0246.namprd13.prod.outlook.com (2603:10b6:208:2ba::11) by MN0PR12MB5764.namprd12.prod.outlook.com (2603:10b6:208:377::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Mon, 15 Apr 2024 12:08:35 +0000 Received: from BL02EPF0001A0F9.namprd03.prod.outlook.com (2603:10b6:208:2ba:cafe::f6) by BL1PR13CA0246.outlook.office365.com (2603:10b6:208:2ba::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.17 via Frontend Transport; Mon, 15 Apr 2024 12:08:35 +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 BL02EPF0001A0F9.mail.protection.outlook.com (10.167.242.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Mon, 15 Apr 2024 12:08:34 +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.986.41; Mon, 15 Apr 2024 05:08:18 -0700 Received: from dev-r-vrt-155.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.1258.12; Mon, 15 Apr 2024 05:08:12 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v2 07/10] ethtool: cmis_cdb: Add a layer for supporting CDB commands Date: Mon, 15 Apr 2024 15:07:14 +0300 Message-ID: <20240415120717.1251864-8-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240415120717.1251864-1-danieller@nvidia.com> References: <20240415120717.1251864-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A0F9:EE_|MN0PR12MB5764:EE_ X-MS-Office365-Filtering-Correlation-Id: 2308c1f2-4aff-4afb-d8c7-08dc5d44c6a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9cCCtf3FuzYkXC2q0plPvagdaf3fxvG/8ICwZqVJWIQYQMo06af03MgixiNn+Agft1YR9xpysywAGp/FoSXZ482uylRD9sx75MUXaF7lnpJGROk9uCGGbKk1jS6NXrNzm9I000j/JY5mdKtaUq0U/KrV4/GRnwFZLYgtgz6lCeROCrA+eN55sv0yYJ1x0aGl5C8alO1Dn61iLUj4gAoswAtadUDy4AJ5k7TOGIUe4wxXQle8k3IpnCeQOyO/j7pnedo2ZLjOgpRJihG9VXExKpfq/V5hZ+zOTnWbbum0MZOr7xbFAqXhWufcrwyVX+EbpexXzHZqFdDRMuRmNsAy8tnXp1Lr21D8eadf1ug0Em80LbGLLOa301bGWfQXxavsua/447NT4qWx400f7xqTCzbjIQwjBecRBF8XOzx4U7CmkGvBk9wNL5k1qQv+dUoSfuCA2ZnDprg4ssBXQhJJB3g83T9zwFundwcFlQAv3WnbTiT2LPLqAdMD3MnKrwoSjStSNEt9WVLUwNak8VKitWGvywhsnrVjrmFnvMtDxlc/LJrAFPYS70StV1/36gP1AwBJj+P6E8KuJ3a+R8WZgRETjdU78Jo/pTjEhMKUv7Cklzp+S2h5zTKhExnKw1EAcrJYgVJW5BH9MEIqFPhBrfvXtDw1zyKu5wY1juwOcuVDYjLQ/W0mShXJqFu+mvmqmZmMvPLyJt1BuX8z+FTUQQT0CLi3CXawohbaYomy6CqPq0Afy1UebirRq1ZWIwAk 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:(13230031)(36860700004)(82310400014)(376005)(7416005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2024 12:08:34.9325 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2308c1f2-4aff-4afb-d8c7-08dc5d44c6a0 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: BL02EPF0001A0F9.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5764 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 --- Notes: v2: * Define ethtool_cmis_cdb_request::epl_len to be __be16 instead of u16. net/ethtool/Makefile | 2 +- net/ethtool/cmis.h | 114 ++++++++ net/ethtool/cmis_cdb.c | 581 ++++++++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 10 + 4 files changed, 706 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..2ade50eec27a --- /dev/null +++ b/net/ethtool/cmis.h @@ -0,0 +1,114 @@ +/* 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. + * @rpl_exp_len: Expected reply length in bytes. + * @flags: Validation flags for CDB commands. + */ +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); +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..8cd64370910b --- /dev/null +++ b/net/ethtool/cmis_cdb.c @@ -0,0 +1,581 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include + +#include "common.h" +#include "module_fw.h" +#include "cmis.h" + +/* For accessing the LPL field on page 9Fh, the allowable length extension is + * min(i, 15) byte octets where i specifies the allowable additional number of + * byte octets in a READ or a WRITE. + */ +u32 ethtool_cmis_get_max_payload_size(u8 num_of_byte_octs) +{ + return 8 * (1 + min_t(u8, num_of_byte_octs, 15)); +} + +void ethtool_cmis_cdb_compose_args(struct ethtool_cmis_cdb_cmd_args *args, + enum ethtool_cmis_cdb_cmd_id cmd, u8 *pl, + u8 lpl_len, u16 max_duration, + u8 read_write_len_ext, u16 msleep_pre_rpl, + u8 rpl_exp_len, u8 flags) +{ + args->req.id = cpu_to_be16(cmd); + args->req.lpl_len = lpl_len; + if (pl) + memcpy(args->req.payload, pl, args->req.lpl_len); + + args->max_duration = max_duration; + args->read_write_len_ext = + ethtool_cmis_get_max_payload_size(read_write_len_ext); + args->msleep_pre_rpl = msleep_pre_rpl; + args->rpl_exp_len = rpl_exp_len; + args->flags = flags; + args->err_msg = NULL; +} + +void ethtool_cmis_page_init(struct ethtool_module_eeprom *page_data, + u8 page, u32 offset, u32 length) +{ + page_data->page = page; + page_data->offset = offset; + page_data->length = length; + page_data->i2c_address = ETHTOOL_CMIS_CDB_PAGE_I2C_ADDR; +} + +#define CMIS_REVISION_PAGE 0x00 +#define CMIS_REVISION_OFFSET 0x01 + +struct cmis_rev_rpl { + u8 rev; +}; + +static inline 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 inline 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) +{ + 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, + "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, "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. + */ +inline 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 inline 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 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, + "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 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, + "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); + if (err < 0) + goto err; + } + + err = cmis_cdb_module_features_get(cdb, dev); + if (err < 0) + goto err; + + return cdb; + +err: + ethtool_cmis_cdb_fini(cdb); + return ERR_PTR(err); +} + +void ethtool_cmis_cdb_fini(struct ethtool_cmis_cdb *cdb) +{ + kfree(cdb); +} + +static bool is_completed(u8 data) +{ + return !!(data & 0x40); +} + +#define CMIS_CDB_STATUS_SUCCESS 0x01 + +static bool status_success(u8 data) +{ + return data == CMIS_CDB_STATUS_SUCCESS; +} + +#define CMIS_CDB_STATUS_FAIL 0x40 + +static bool status_fail(u8 data) +{ + return data & CMIS_CDB_STATUS_FAIL; +} + +struct cmis_wait_for_cond_rpl { + u8 state; +}; + +int ethtool_cmis_wait_for_cond(struct net_device *dev, u8 flags, u8 flag, + u16 max_duration, u32 offset, + bool (*cond_success)(u8), bool (*cond_fail)(u8), + u8 *state) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + struct ethtool_module_eeprom page_data = {0}; + struct cmis_wait_for_cond_rpl rpl = {}; + struct netlink_ext_ack extack = {}; + unsigned long end; + int err; + + if (!(flags & flag)) + return 0; + + if (max_duration == 0) + max_duration = U16_MAX; + + end = jiffies + msecs_to_jiffies(max_duration); + do { + ethtool_cmis_page_init(&page_data, 0, offset, sizeof(rpl)); + page_data.data = (u8 *)&rpl; + + err = ops->get_module_eeprom_by_page(dev, &page_data, &extack); + if (err < 0) { + if (extack._msg) + netdev_err(dev, "%s\n", extack._msg); + continue; + } + + if ((*cond_success)(rpl.state)) + return 0; + + if (*cond_fail && (*cond_fail)(rpl.state)) + break; + + msleep(20); + } while (time_before(jiffies, end)); + + *state = rpl.state; + return -EBUSY; +} + +#define CMIS_CDB_COMPLETION_FLAG_OFFSET 0x08 + +static int cmis_cdb_wait_for_completion(struct net_device *dev, + struct ethtool_cmis_cdb_cmd_args *args) +{ + u8 flag; + int err; + + /* Some vendors demand waiting time before checking completion flag + * in some CDB commands. + */ + msleep(args->msleep_pre_rpl); + + err = ethtool_cmis_wait_for_cond(dev, args->flags, + CDB_F_COMPLETION_VALID, + args->max_duration, + CMIS_CDB_COMPLETION_FLAG_OFFSET, + is_completed, NULL, &flag); + if (err < 0) + args->err_msg = "Completion Flag did not set on time"; + + return err; +} + +#define CMIS_CDB_STATUS_OFFSET 0x25 + +static void cmis_cdb_status_fail_msg_get(u8 status, char **err_msg) +{ + switch (status) { + case 0b10000001: + *err_msg = "CDB Status is in progress: Busy capturing command"; + break; + case 0b10000010: + *err_msg = + "CDB Status is in progress: Busy checking/validating command"; + break; + case 0b10000011: + *err_msg = "CDB Status is in progress: Busy executing"; + break; + case 0b01000000: + *err_msg = "CDB status failed: no specific failure"; + break; + case 0b01000010: + *err_msg = + "CDB status failed: Parameter range error or parameter not supported"; + break; + case 0b01000101: + *err_msg = "CDB status failed: CdbChkCode error"; + break; + default: + *err_msg = "Unknown failure reason"; + } +}; + +static int cmis_cdb_wait_for_status(struct net_device *dev, + struct ethtool_cmis_cdb_cmd_args *args) +{ + u8 status; + int err; + + /* Some vendors demand waiting time before checking status in some + * CDB commands. + */ + msleep(args->msleep_pre_rpl); + + err = ethtool_cmis_wait_for_cond(dev, args->flags, CDB_F_STATUS_VALID, + args->max_duration, + CMIS_CDB_STATUS_OFFSET, + status_success, status_fail, &status); + if (err < 0 && !args->err_msg) + cmis_cdb_status_fail_msg_get(status, &args->err_msg); + + return err; +} + +#define CMIS_CDB_REPLY_OFFSET 0x86 + +static int cmis_cdb_process_reply(struct net_device *dev, + struct ethtool_module_eeprom *page_data, + struct ethtool_cmis_cdb_cmd_args *args) +{ + u8 rpl_hdr_len = sizeof(struct ethtool_cmis_cdb_rpl_hdr); + u8 rpl_exp_len = args->rpl_exp_len + rpl_hdr_len; + const struct ethtool_ops *ops = dev->ethtool_ops; + struct netlink_ext_ack extack = {}; + struct ethtool_cmis_cdb_rpl *rpl; + int err; + + if (!args->rpl_exp_len) + return 0; + + ethtool_cmis_page_init(page_data, ETHTOOL_CMIS_CDB_CMD_PAGE, + CMIS_CDB_REPLY_OFFSET, rpl_exp_len); + page_data->data = kmalloc(page_data->length, GFP_KERNEL); + if (!page_data->data) + return -ENOMEM; + + err = ops->get_module_eeprom_by_page(dev, page_data, &extack); + if (err < 0) { + if (extack._msg) + netdev_err(dev, "%s\n", extack._msg); + goto out; + } + + rpl = (struct ethtool_cmis_cdb_rpl *)page_data->data; + if ((args->rpl_exp_len > rpl->hdr.rpl_len + rpl_hdr_len) || + !rpl->hdr.rpl_chk_code) { + err = -EIO; + goto out; + } + + args->req.lpl_len = rpl->hdr.rpl_len; + memcpy(args->req.payload, rpl->payload, args->req.lpl_len); + +out: + kfree(page_data->data); + return err; +} + +static int +__ethtool_cmis_cdb_execute_cmd(struct net_device *dev, + struct ethtool_module_eeprom *page_data, + u8 page, u32 offset, u32 length, void *data) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + struct netlink_ext_ack extack = {}; + int err; + + ethtool_cmis_page_init(page_data, page, offset, length); + page_data->data = kmalloc(page_data->length, GFP_KERNEL); + if (!page_data->data) + return -ENOMEM; + + memcpy(page_data->data, data, page_data->length); + + 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 e40eae442741..96da7a8175f2 100644 --- a/net/ethtool/module_fw.h +++ b/net/ethtool/module_fw.h @@ -8,3 +8,13 @@ void ethnl_module_fw_flash_ntf_start(struct net_device *dev); void ethnl_module_fw_flash_ntf_complete(struct net_device *dev); void ethnl_module_fw_flash_ntf_in_progress(struct net_device *dev, u64 done, u64 total); + +/** + * 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; +}; From patchwork Mon Apr 15 12:07:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13629886 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2043.outbound.protection.outlook.com [40.107.243.43]) (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 5D12B6BFC0; Mon, 15 Apr 2024 12:08:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182924; cv=fail; b=YclU6xo/qyxoh8O4e/57olENCzanmir8jFLi17icw6/8G/5PlQ/CDgsCMoC0TufZZAeGNGbv2/WRqvyT1SOyjkUO2xqu/qwGO3GvvqYB0n/JdZd5OlKRFozVj9X/qyMd0Ykr3wld0g23eGBckG3m237ztGlQmqjzrUj+I0jTnko= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182924; c=relaxed/simple; bh=UxUWlh4KI1/q38rdJiUwyA8npYlCyBQ+M8Ey4+zIe5U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ci0qplMNe8nlrOryuMNnjzBKOeHPmu0tZBdJt71bIe47zaKlfBgNtgyuwnRqG0FuE2c0nFQqHztL+lwJv/q5u2H5YArB4RSxO09kAojzbosgPI6jD9UcxRioQGT+qswb27bkAsNHj+cNfRcDeKcqCbseFiy2Ou+u8jLwB9kiZD0= 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=X73mmABJ; arc=fail smtp.client-ip=40.107.243.43 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="X73mmABJ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oTmT3Pv14qwjQ3RnanExrOBXvg4AWt69tY7gkvsFQt7DuR+oV0PuubBhreDN+znNErdlqHG5fu2o/C6/ATr6UjOFI70JrgoAnSlKP2J28pfgWQlPQlKOa9gdcNxMxvFL/C+u4SsUX4LtOBqgcbHWELq5055a/VdNwqsR99mNWqqj+tyE5kd04tKzhBhneURkEz7Q1h31+wMAgkZ414bFk89NakZ/rDolRnSrnWqwaOU+jqdy4HcO7LHcVrFWYj5wCzTLEDe9A8/3gUNkr6ad4ulCp9M3STL3R0yTwkxzCdguqp8AE9E5DhDSqw9e7/sLhf51gN1D4qNtVtNxnkOoQA== 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=51LVe65ebhP4GG4o5EomnRlFeoOIDaL/P4yU3sneogQ=; b=JjraKUAcWnEhL/jYTilKs+EXd74q3vfSVOSUCLFHG2dOLncXYHzsI84VvF9qnsrd5LUN6lCBdto3jvKshwKiB5IEonVVycW8NfLPAaNkz4Tsmh/esv6rBB1MuR4fqIJfmoWlrgnauoGgbYAmP7u5O99tjkAS7sJDH+W28BTClp8njiqesIpUuUx1ThXbsU6YIRBeMqoi6GUFCe2wMC75JLz4oZfefJYNGuimqE4Qd1kZmgbvQqaajhBA3U7y80lwseiVMr21kATKatjqXRh9SWxAW6WjLOO1nB3I4IatZb14BZltIL1hYEZa/aGKLa264yQtXccUZ6tE1MwMjcje5w== 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=51LVe65ebhP4GG4o5EomnRlFeoOIDaL/P4yU3sneogQ=; b=X73mmABJdjmM8GAtFqUj5SGF9SbiEW5XmmV91kOXqOTVLmiIRtv3xdbIsKQeknWRHHoDKMBlQ4JcWLl9OrN1aocaxuP9G73EhWvcNegrQf9PAfOCCclawSnYl+tS6BBnZlaUOwcBaL3ZR+9wjKMEhvx1Y42zENr5aOxQ+gs8hMVwMN1m44wJr0xdGbfyGtBKtyg4eE/YXtERwiD7SQpF4y798cojpvJwV4jkqGMPQfieN526kY/0teCBJPx6Vbbc0h3n2aIbN6JTF/NPfQVRCc84gz7To0+YnOXV7fK7RM9/gBFNyDgViateGUxiBQMeec315cbrqMLdz0OGE5OgEA== Received: from CY5P221CA0004.NAMP221.PROD.OUTLOOK.COM (2603:10b6:930:b::12) by MW6PR12MB8951.namprd12.prod.outlook.com (2603:10b6:303:244::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.49; Mon, 15 Apr 2024 12:08:36 +0000 Received: from CY4PEPF0000EE3A.namprd03.prod.outlook.com (2603:10b6:930:b:cafe::35) by CY5P221CA0004.outlook.office365.com (2603:10b6:930:b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.33 via Frontend Transport; Mon, 15 Apr 2024 12:08:36 +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 CY4PEPF0000EE3A.mail.protection.outlook.com (10.167.242.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Mon, 15 Apr 2024 12:08:35 +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.986.41; Mon, 15 Apr 2024 05:08:24 -0700 Received: from dev-r-vrt-155.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.1258.12; Mon, 15 Apr 2024 05:08:18 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v2 08/10] ethtool: cmis_fw_update: add a layer for supporting firmware update using CDB Date: Mon, 15 Apr 2024 15:07:15 +0300 Message-ID: <20240415120717.1251864-9-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240415120717.1251864-1-danieller@nvidia.com> References: <20240415120717.1251864-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3A:EE_|MW6PR12MB8951:EE_ X-MS-Office365-Filtering-Correlation-Id: 0848708e-0265-4ef8-d8cf-08dc5d44c73b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pF73NUH/FmhEU9JihIca6mpxvdFFhbO/nmupA5er2rgrILl0cQt95x0ODapLJPTywGArG7d5R74sF/QL1mVRWz5GUzQYUv8q3KYFOjkvFKaTQB2uFjkBeCDlD6QDVb0iz85wDiOmb/D/d8aKRmn3Eu3rY1Zr/An1lLArvExOwSD7KtbzpN1vIgtLq+2ZDYkxfZZP7TEHApVc+mD4YsQAkA1r65ElhqxjFuebglDaqPCHc9ruXuvhvEINrfI7lR6rDFYTsLjxHOuEVrQTeyJ7XrmXXTpsFrC6ppCSC0UYhupmSk4Z8X3D48coxQiqqJ5XMveEn6yAEzzFZ+Ebr6uPmBjwESq/53TP1eU8ifkIg9ITbbt6D9qF+3qNLBb/y3SfrKyXCh96YKiLoW5BQfV+TJk2sRODZjjOSlsIrfPl7UNP+NVZLsRRsBgvu7YlIr3IrT15XHFm9Fw3sMgmlZAFFHi9r3FNLyDkThXsAIJo+aMhqhdgcbzjsEnCkHbocyNO3nh/WZmgPobnKHzwIOkUBGuNpKC1BYWhVLQJha1ZcJvGPyuPga+Zs5/u8cAdFx0mkQqHM1govZkIrSvjPXW+OelANCgJGdUOVqH9ErSGndScZALOZMG7GdFwoSqRBQQWzM090lK4OyOB2RLADyG3dE+ae6Bk2Y/FF6xC+Al19MmbAICD0y3ibB2IA65S5K8leONz/L5N0LHcrBEe1HiZoRAQraUvpQVuU5Nr4GPv7t8jqDv+YiZeYwYPTlm9Nbbw 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:(13230031)(376005)(1800799015)(7416005)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2024 12:08:35.9952 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0848708e-0265-4ef8-d8cf-08dc5d44c73b 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: CY4PEPF0000EE3A.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8951 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 --- Notes: 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 | 397 +++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 18 ++ 4 files changed, 423 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 2ade50eec27a..f46c87991697 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..a23ff2c86a8a --- /dev/null +++ b/net/ethtool/cmis_fw_update.c @@ -0,0 +1,397 @@ +// 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 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, + "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, + "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_module_fw_flash *module_fw, + 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(module_fw->fw->size); + memcpy(pl.vendor_data, module_fw->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(module_fw->dev, &args); + if (err < 0) + ethnl_module_fw_flash_ntf_err(module_fw->dev, + "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_module_fw_flash *module_fw, + struct cmis_fw_update_fw_mng_features *fw_mng) +{ + u8 start = fw_mng->start_cmd_payload_size; + u32 image_size = module_fw->fw->size; + u32 offset, max_block_size, max_lpl_len; + 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(module_fw->dev, + offset - start, + image_size); + block_size = min_t(u32, max_block_size, image_size - offset); + memcpy(pl.fw_block, &module_fw->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(module_fw->dev, &args); + if (err < 0) { + ethnl_module_fw_flash_ntf_err(module_fw->dev, + "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 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, + "Complete FW download command failed", + args.err_msg); + + return err; +} + +static int +cmis_fw_update_download_image(struct ethtool_cmis_cdb *cdb, + struct ethtool_module_fw_flash *module_fw, + struct cmis_fw_update_fw_mng_features *fw_mng) +{ + int err; + + err = cmis_fw_update_start_download(cdb, module_fw, fw_mng); + if (err < 0) + return err; + + err = cmis_fw_update_write_image(cdb, module_fw, fw_mng); + if (err < 0) + return err; + + err = cmis_fw_update_complete_download(cdb, module_fw->dev, fw_mng); + 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_USEC 1000 +#define CMIS_MODULE_STATE_OFFSET 3 + +static int +cmis_fw_update_wait_for_module_state(struct ethtool_module_fw_flash *module_fw, + u8 flags) +{ + u8 state; + + return ethtool_cmis_wait_for_cond(module_fw->dev, flags, + CDB_F_MODULE_STATE_VALID, + CMIS_MODULE_READY_MAX_DURATION_USEC, + 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 ethtool_module_fw_flash *module_fw) +{ + 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(module_fw->dev, &args); + if (err < 0) { + ethnl_module_fw_flash_ntf_err(module_fw->dev, + "Run image command failed", + args.err_msg); + return err; + } + + err = cmis_fw_update_wait_for_module_state(module_fw, args.flags); + if (err < 0) + ethnl_module_fw_flash_ntf_err(module_fw->dev, + "Module is not ready on time after reset", + NULL); + + return err; +} + +static int +cmis_fw_update_commit_image(struct ethtool_cmis_cdb *cdb, + struct ethtool_module_fw_flash *module_fw) +{ + 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(module_fw->dev, &args); + if (err < 0) + ethnl_module_fw_flash_ntf_err(module_fw->dev, + "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 work_struct *work) +{ + struct cmis_fw_update_fw_mng_features fw_mng = {0}; + struct ethtool_module_fw_flash *module_fw; + struct ethtool_cmis_cdb *cdb; + int err; + + module_fw = container_of(work, struct ethtool_module_fw_flash, work); + + cdb = ethtool_cmis_cdb_init(module_fw->dev, &module_fw->params); + if (IS_ERR(cdb)) + goto err_send_ntf; + + ethnl_module_fw_flash_ntf_start(module_fw->dev); + + err = cmis_fw_update_fw_mng_features_get(cdb, module_fw->dev, &fw_mng); + if (err < 0) + goto err_cdb_fini; + + err = cmis_fw_update_download_image(cdb, module_fw, &fw_mng); + if (err < 0) + goto err_cdb_fini; + + err = cmis_fw_update_run_image(cdb, module_fw); + 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(module_fw->dev, &module_fw->params); + if (IS_ERR(cdb)) + goto err_send_ntf; + + err = cmis_fw_update_commit_image(cdb, module_fw); + if (err < 0) + goto err_cdb_fini; + + err = cmis_fw_update_reset(module_fw->dev); + if (err < 0) + goto err_cdb_fini; + + ethnl_module_fw_flash_ntf_complete(module_fw->dev); + ethtool_cmis_cdb_fini(cdb); + goto out; + +err_cdb_fini: + ethtool_cmis_cdb_fini(cdb); +err_send_ntf: + ethnl_module_fw_flash_ntf_err(module_fw->dev, NULL, NULL); +out: + module_fw->dev->module_fw_flash_in_progress = false; + netdev_put(module_fw->dev, &module_fw->dev_tracker); + release_firmware(module_fw->fw); + kfree(module_fw); +} diff --git a/net/ethtool/module_fw.h b/net/ethtool/module_fw.h index 96da7a8175f2..9af5b15efe85 100644 --- a/net/ethtool/module_fw.h +++ b/net/ethtool/module_fw.h @@ -9,6 +9,8 @@ void ethnl_module_fw_flash_ntf_complete(struct net_device *dev); void ethnl_module_fw_flash_ntf_in_progress(struct net_device *dev, u64 done, u64 total); +void ethtool_cmis_fw_update(struct work_struct *work); + /** * struct ethtool_module_fw_flash_params - module firmware flashing parameters * @password: Module password. Only valid when @pass_valid is set. @@ -18,3 +20,19 @@ struct ethtool_module_fw_flash_params { __be32 password; u8 password_valid:1; }; + +/** + * struct ethtool_module_fw_flash - module firmware flashing + * @dev: Pointer to the net_device to be flashed. + * @dev_tracker: Refcount tracker for @dev. + * @params: Module firmware flashing parameters. + * @work: The flashing firmware work. + * @fw: Firmware to flash. + */ +struct ethtool_module_fw_flash { + struct net_device *dev; + netdevice_tracker dev_tracker; + struct ethtool_module_fw_flash_params params; + struct work_struct work; + const struct firmware *fw; +}; From patchwork Mon Apr 15 12:07:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13629888 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2056.outbound.protection.outlook.com [40.107.223.56]) (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 04DD971733; Mon, 15 Apr 2024 12:08:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182937; cv=fail; b=DGGvH0Qc47lIHT9SkUpVspgnV5tcnMZaEIoTcWhT+N86HXn5bTu1mh5+oom9gMZsgCzLUWG10DJ7WNc6Mp6bHV2tOGV1a067m+S78U3rcoj32Mv3q18QXEI5hUUctzmzPUsSW7SKNlSgpLd+MHzcutL7fg7icnmK9KczIGCMZKI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182937; c=relaxed/simple; bh=AfMSgWSQr14Kq7RRN+mCLxiDZzv7bYqh+EGqO3emaZE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rTHSckYU1bn+kGbT0mh7+yos0YzKu2sHoLhql2sIQSdrCvlgXzNbqhwDOWx4YPmmmMOqTmUZAMPZ8AYQfeYYmpqJ6SVGBjyEYviPb035Mvk8pvH5lj4TeVLLu3oZFCuC5n1DzIg6I0LsLX3vVixY8EvHNneB5P5V9rqXR11+V/4= 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=gLwAWVbK; arc=fail smtp.client-ip=40.107.223.56 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="gLwAWVbK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kqm2gVZ5GmdAnFbvZYcEvtp5LZ3xUan/4ScVg1MCt6b/iA+t55/aFIblsKJx2D4cFAIyamyn14hMKV5K4XkDNhr5mxk45H4oOFEkBKFJSmRAVNRh858opkh16XDJ2hTGsBa5CVLGfWSN/81rX8/Ijjy0XyvTuvqZIorsqVZS8nd+/UY7spG4SIwFiP2YqmNXnjJwkv6bVfvgiPgP2SIwR8jB1h4VI3BNgQqQvAzd+wanEMG2bSlEmiLqtMEJzfb60xbNyjCB17dJKayOfgpELzAZowgkc9RAF6usJ4b5aE78u6XHmYqSAvkhAf7mS5XHO15eautqeUdhA5JZIEcI2Q== 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=38Gdhk3KN04AsB2+FtnOPufQa9OPd0VNkEYGnuMTvIE=; b=eU358+iUYh5bFS6C4F2+KAob5htZRSDWiEJHHDomBpxkDQ2QiZ1HPp8qb16iqZEOVqZTodIrhDkC03isXQVgDr01m0uV1Q1wKZw5Iy03w8cZrlGh151l9BFUSkH/Z2TYxX9CZBxV+vkk4TD0YS1E224/lC3y5gYR1wBcVCBMEuYSQSpvc3juKh7SOiY0ItwEIbes+7hz6fGJ2gZJ1fAAo+vB8F0VjtkuOt+HTYNx1nIn+AJSTfWl09e8YjtZ9B56QlUgNvk4u2ftYnn8y/GrQFEHeUuEYliTWs7+Vtdqtd2AChtJvdsjgaU0kfFTF77yg1P0kuMszQMrlgu62IxvJA== 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=38Gdhk3KN04AsB2+FtnOPufQa9OPd0VNkEYGnuMTvIE=; b=gLwAWVbKijzwuuIGWefgpaIQUZ+JzczNCVxQEPa28IbbQPFzJ3b7XGQ4PAHTHtL1P6jPYzFTgQAoOKcuPokkoaOPVxIP2K+cAyR4O5xZ8DQ0ApBCx1QHrIBdCi6pF84MRQeGKmIZPAgpIxtxvTqxCkMdIsLy400O6NN0f/4ofbFLbmK61MreNSvsEkiJ2qwOSemGv99Erg5OunJd7t04VwHnCFvlavPlTJ6D5nV5ZOWENgsyDl3mJ4692TFqTVAFxJHsg0zJZ8LWByRRXgrwHCuqbExKkF3cnIXGLJ+Y7uRXRUo6/MQ9Z+C35KG/+Zp7/xphApT8orccwmsfOCWATA== Received: from MN2PR01CA0063.prod.exchangelabs.com (2603:10b6:208:23f::32) by DS0PR12MB7770.namprd12.prod.outlook.com (2603:10b6:8:138::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Mon, 15 Apr 2024 12:08:49 +0000 Received: from BL02EPF0001A0FD.namprd03.prod.outlook.com (2603:10b6:208:23f:cafe::97) by MN2PR01CA0063.outlook.office365.com (2603:10b6:208:23f::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.33 via Frontend Transport; Mon, 15 Apr 2024 12:08:49 +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 BL02EPF0001A0FD.mail.protection.outlook.com (10.167.242.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Mon, 15 Apr 2024 12:08:49 +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.986.41; Mon, 15 Apr 2024 05:08:30 -0700 Received: from dev-r-vrt-155.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.1258.12; Mon, 15 Apr 2024 05:08:24 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v2 09/10] ethtool: Add ability to flash transceiver modules' firmware Date: Mon, 15 Apr 2024 15:07:16 +0300 Message-ID: <20240415120717.1251864-10-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240415120717.1251864-1-danieller@nvidia.com> References: <20240415120717.1251864-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A0FD:EE_|DS0PR12MB7770:EE_ X-MS-Office365-Filtering-Correlation-Id: 00ecc4df-3a5a-46d9-3e57-08dc5d44cf2e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Sq6kDZUyYIoxOlMdceVhGbqgkzIBRkTdeyKHDtHNIW+3Tfa/AAa3msdMSJmjGeWXOrON4/uWAqBqtODjGexHQDoqlSGdCyTMaWN10tUtDwHKyEqc0CSoIR6uiarWFR2wTOkbxMk1V9yHpoKnsw1df1qynY79nmxKNCLk2vTIAanjTipQVAlKYU1lhDKnLDawG/sKPdqFxmQs3p+RBeHzs13dYqaOnQBy8Sc0/Y/8+SqixdYj84gq+Z3NVY2t+zstNUhU73xeP+NbOCJBE+qa3be9lhrdBcaoTx02hKxhklUB3TRkus+J3HRpYZik+0S5Jc5luD2KmIiY1der2OS67V0X0/E6XEaM/7aGrgddkKo/eqcZtdnB6Vsn8fVWNkxnaz2rqE41oOHYiZR4PiQI9R8w5oqn92xTM4OVwDh+u0vYD++p9k/MSY+3adRkibzolG/NvP78TuWyPQW7ZTD3aGCG3NLNYPKWfX1NSLwvvhnuyQJltsyxJLFk/Irvs7J6dXADZ1lNMZpy1R7n9J9l4oRCg7y7996b8WOes/o5httabHM0qnoKBuC9fR2fYof+Uwd6uzYjQNQmNt54pEokO2+ZZ47fRGdZoriTGIku4I5Eb8XBJp+4rPTE1bQtlG6KvC43R7se4yJOR5aXJSabd8Mu5X4QX5E9Q6hwy0su66lThQiXJTEV67Mfujqn2jHVYisv4FaaxYtPt2ouIhTnuZRheG5NSD8An/pamTz7QYb0ka750H0z9nhOflFy1R6M 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:(13230031)(36860700004)(7416005)(1800799015)(82310400014)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2024 12:08:49.2810 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 00ecc4df-3a5a-46d9-3e57-08dc5d44cf2e 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: BL02EPF0001A0FD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7770 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 eth0 Transceiver module firmware flashing in progress for device eth0 Status message: Downloading firmware image Progress: 0% [...] Transceiver module firmware flashing in progress for device eth0 Status message: Downloading firmware image Progress: 50% [...] Transceiver module firmware flashing in progress for device eth0 Status message: Downloading firmware image Progress: 100% Transceiver module firmware flashing completed for device eth0 Signed-off-by: Danielle Ratson --- net/ethtool/module.c | 174 ++++++++++++++++++++++++++++++++++++++++++ net/ethtool/netlink.c | 7 ++ net/ethtool/netlink.h | 2 + 3 files changed, 183 insertions(+) diff --git a/net/ethtool/module.c b/net/ethtool/module.c index 1c659bd85160..836c198d2cc4 100644 --- a/net/ethtool/module.c +++ b/net/ethtool/module.c @@ -1,6 +1,8 @@ // SPDX-License-Identifier: GPL-2.0-only #include +#include +#include #include "netlink.h" #include "common.h" @@ -160,6 +162,178 @@ 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 }, +}; + +#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, ethtool_cmis_fw_update); + break; + default: + NL_SET_ERR_MSG(extack, + "Module type does not support firmware flashing"); + return -EOPNOTSUPP; + } + + return 0; +} + +static int __module_flash_fw_schedule(struct net_device *dev, + struct netlink_ext_ack *extack) +{ + 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; + } + + return 0; +} + +static int +module_flash_fw_schedule(struct net_device *dev, const char *file_name, + struct ethtool_module_fw_flash_params *params, + struct netlink_ext_ack *extack) +{ + struct ethtool_module_fw_flash *module_fw; + int err; + + err = __module_flash_fw_schedule(dev, extack); + if (err < 0) + return err; + + module_fw = kzalloc(sizeof(*module_fw), GFP_KERNEL); + if (!module_fw) + return -ENOMEM; + + module_fw->params = *params; + err = request_firmware_direct(&module_fw->fw, file_name, &dev->dev); + if (err) { + NL_SET_ERR_MSG(extack, + "Failed to request module firmware image"); + goto err_request_firmware; + } + + err = module_flash_fw_work_init(module_fw, dev, extack); + if (err < 0) { + NL_SET_ERR_MSG(extack, + "Flashing module firmware is not supported by this device"); + goto err_work_init; + } + + dev->module_fw_flash_in_progress = true; + netdev_hold(dev, &module_fw->dev_tracker, GFP_KERNEL); + module_fw->dev = dev; + + schedule_work(&module_fw->work); + + return 0; + +err_work_init: + release_firmware(module_fw->fw); +err_request_firmware: + kfree(module_fw); + return err; +} + +static int module_flash_fw(struct net_device *dev, struct nlattr **tb, + 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, info->extack); +} + +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 = module_flash_fw(dev, tb, info); + + ethnl_ops_complete(dev); + +out_rtnl: + rtnl_unlock(); + ethnl_parse_header_dev_put(&req_info); + return ret; +} + /* MODULE_FW_FLASH_NTF */ static void diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 563e94e0cbd8..1a4f6bd1ec7f 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -1169,6 +1169,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[] = { diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index d57a890b5d9e..e1e2edd05206 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -446,6 +446,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); @@ -453,6 +454,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]; From patchwork Mon Apr 15 12:07:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13629889 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2055.outbound.protection.outlook.com [40.107.237.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 8F6D970CD8; Mon, 15 Apr 2024 12:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182938; cv=fail; b=U4m46pDf+nYVBiTU0+wHj3WL6OWaYy5CVI4JuMphHMOzLlJ+KIzARdBu3O0PJBtC5iDGpbPxioFpzwt+h+T/pcG9D4PSlDaUFmzl+plBBYSP2UKj4+FQ2oBAQoMhPdGMODiYy2UAh6Qg4JipjpXBLKwUADaE/jQ4LxiUFAbcvK0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713182938; c=relaxed/simple; bh=yZfvoGxUnvDaatNkkEDXy9xr1YOYnlqdKwLC2dw6GmE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SDHr/h79vmCtCf+E44z2MiW+qviJ90K1VYfxdYIZJhEr5DrYDTWfxn72fc9IXCP8LSP1ZtUSnPLkEnTXXWgpfPGGZsmzJeL0ybE2BNk2PUR9F5E/jXSdsqGvwd1q+DoCJKCs5y7VKMJ/C6QBI4B+tNHA8NkCk4hCUrElysw3JLI= 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=XId01Qqg; arc=fail smtp.client-ip=40.107.237.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="XId01Qqg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l94p3nbqH6bnqkS84DioeiPFpG4MtKRMafo36MEVapUVBZeYx9/9EMXJHfNJHDTcj4KiPW8xzhi5tuvXHKczHpli3CLVJc5Ney3G+M1vd0bPq69mL3d1xomWTTwAlcqR38OcZ23+TpL+nqOHmEceqHPbsSJJ1b/5pZ/rpwqblpT9EAgONxopkz8l2DBmLj4Li950qtwlhVmNKF/s/LRrK+EtYysL+Gqc9Zy0bqLDC32GU2PZ43rMDUUR9Y/DpYEPvy2MV2wYVxiit0rkCvWkbjwG4CCJ/V7/SmDyWb58aqE2UyIZ6hq5mpPNzBFtDYTY/+Wb5nmNNhPOg6Xch2ZXMw== 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=cP2K2/ziAy9DPxkA8GJpo5t/WSRjiRBCvqdWzB4ohOM=; b=YYMGRJ8Gix07HhYn2eR3J5dO7KF3jSKoqGHwSWucVFI/2hYfS7w0bhz4n2FYW7GHpM59c5Hz/XtBFVIaaNVCGNEU0boZ4uSULIwmmBCnIk4p8qYudnnCxhxK8uHkzergswnGFow6NwJ1RAmnqFJ4QruLqv6eLz2gEzhi29L7NaD3ngLvswqY65eU4lRqW/3hx+Ftf/3Nkl9P4um/HRMU5qQvKSvHEGXZ7fV6Ibsn4I7HIomvU5BZCzplveoN45615twQAZstakOqF+ViOBwMiEgqVuIvvFZ5H4ofBScSH5M/PQi1+p4mHsJ56R2I4bk9FwZQU5QddFgaRmhzWbj8VQ== 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=cP2K2/ziAy9DPxkA8GJpo5t/WSRjiRBCvqdWzB4ohOM=; b=XId01QqgaPz4ovKb2KUdYs6kDPnUmQwIlVqgbNJNqB0y+AN9MnLgVLWwHiNgA8pNAhngZbrg5/1ofwfc0ERZESXuwa6dwvndRAQQwvuP3WVsvQ9/D19qfKlnMsFtXUJR6XzAemuHG9cxaJQLzPHOJnCfhryC1kPXGc/EufN2kQ5/WxurxF2AVedoFfWojXxiPO5EHObMoftN6pUKSZNRJKRA0r9HewLxvJajhzp9NPHuv9JKyPVzmuOYWjgX/4VLG7VfURVkXcGkjFPF1IZXoJ5dwgDCWLIDtq+eJQQeS6byDpoRCOsMxnfG6k5bw0+dlg4RQummzEUwNDe+0iTA5A== Received: from SJ0PR05CA0161.namprd05.prod.outlook.com (2603:10b6:a03:339::16) by PH7PR12MB5593.namprd12.prod.outlook.com (2603:10b6:510:133::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Mon, 15 Apr 2024 12:08:53 +0000 Received: from CY4PEPF0000EE3E.namprd03.prod.outlook.com (2603:10b6:a03:339:cafe::af) by SJ0PR05CA0161.outlook.office365.com (2603:10b6:a03:339::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.17 via Frontend Transport; Mon, 15 Apr 2024 12:08: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 CY4PEPF0000EE3E.mail.protection.outlook.com (10.167.242.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Mon, 15 Apr 2024 12:08: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.986.41; Mon, 15 Apr 2024 05:08:36 -0700 Received: from dev-r-vrt-155.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.1258.12; Mon, 15 Apr 2024 05:08:30 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v2 10/10] ethtool: Veto some operations during firmware flashing process Date: Mon, 15 Apr 2024 15:07:17 +0300 Message-ID: <20240415120717.1251864-11-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240415120717.1251864-1-danieller@nvidia.com> References: <20240415120717.1251864-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3E:EE_|PH7PR12MB5593:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f3e323e-98c2-4c9a-f3e4-08dc5d44d17e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XTmP5YEeCOLB+mGeVOuGVFUfz8pe+WVcSXXOYkfjGcsnxDgzFy+V9gubpouG91msOW9Ht+KBy3KPfuseRWb3Cdj8wGrTS40haCIQnBlPNs0PZFFsCMpjXanpupdxDfvuClQqC+V4+kA8oTqEZTbc+j4vldNtSFookyfo18OzaLlSxIP9lTghzV1tH4+K6ZQiFEnpWx1wCpkgmDA1iNepX+cPfmMvC6p6mwZU5MamojqIwLO1iqkCkwHVXOX4/+4RjyQOlf9uOvS6ofUl6IQKPW+u/dAAtJGcpIuKFeVyL0Sl6XpQF2BYi96Zb3S/1UpllQZDsAKdS3MnWvG4SB/IMHwrM9Ck8y7shonlD948Fei4jtoRf8oDtBiNCQwlur28OBUNCySe6I2sd7SKQAid4dUMmzhAg2tuH7AXvRz5GB0BboJiT9yOL+VwZsoQ7E2NNKBmbgS1bIaSmcrR7yLc+vF2JERsUbc+9k9AhSCdEoIhfwakBgqMguq/2THo3btUD2fu3aUbLyzwkoSrDzEwuVSH/z9NecoHoDCLssMABZ8ufnAQx3xaI6bHP+meqzp95sNkpe2MEgoWiIrabJatgAJpnOceaWzDeJ/K/PWH34Zv6aCMjAHod7HSzVY6MD8yyU0uwz+/LajOGGouFxifgWuEMnercz1As8XONScCJcRWeTvWGWtsHvsL/5ayuKZG3M0tAgQzNkgPFZVgdBUPO5tjM7L6cjZvEu3ytHrdG0bdWsQ/EcrQg+dVAEqF8ReQ 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:(13230031)(7416005)(82310400014)(1800799015)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2024 12:08:53.2122 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f3e323e-98c2-4c9a-f3e4-08dc5d44d17e 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: CY4PEPF0000EE3E.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5593 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. - Flashing firmware on a device which is already in a flashing process should be forbidden. Use the 'module_fw_flashing_in_progress' flag introduced in a previous patch to veto those operations and prevent interruptions while preforming module firmware flash. Signed-off-by: Danielle Ratson --- net/ethtool/eeprom.c | 6 ++++++ net/ethtool/ioctl.c | 12 ++++++++++++ net/ethtool/module.c | 29 +++++++++++++++++++++++++++++ net/ethtool/netlink.c | 30 +++++++++++++++++++++++++++++- 4 files changed, 76 insertions(+), 1 deletion(-) 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 5a55270aa86e..02b23805d2be 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/module.c b/net/ethtool/module.c index 836c198d2cc4..239e7974f952 100644 --- a/net/ethtool/module.c +++ b/net/ethtool/module.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "netlink.h" #include "common.h" @@ -36,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); } @@ -112,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], @@ -219,6 +232,7 @@ static int module_flash_fw_work_init(struct ethtool_module_fw_flash *module_fw, static int __module_flash_fw_schedule(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 || @@ -234,6 +248,21 @@ static int __module_flash_fw_schedule(struct net_device *dev, 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; } diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 1a4f6bd1ec7f..90e5b5312aa2 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -1194,6 +1194,29 @@ static struct genl_family ethtool_genl_family __ro_after_init = { .n_mcgrps = ARRAY_SIZE(ethtool_nl_mcgrps), }; +static int module_netdev_pre_up_event(struct notifier_block *this, + unsigned long event, void *ptr) +{ + struct net_device *dev = netdev_notifier_info_to_dev(ptr); + struct netdev_notifier_info *info = ptr; + struct netlink_ext_ack *extack; + + extack = netdev_notifier_info_to_extack(info); + + if (event == 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; +} + +static struct notifier_block ethtool_module_netdev_pre_up_notifier = { + .notifier_call = module_netdev_pre_up_event, +}; + /* module setup */ static int __init ethnl_init(void) @@ -1206,7 +1229,12 @@ static int __init ethnl_init(void) ethnl_ok = true; ret = register_netdevice_notifier(ðnl_netdev_notifier); - WARN(ret < 0, "ethtool: net device notifier registration failed"); + if (WARN(ret < 0, "ethtool: net device notifier registration failed")) + return ret; + + ret = register_netdevice_notifier(ðtool_module_netdev_pre_up_notifier); + WARN(ret < 0, "ethtool: net device port up notifier registration failed"); + return ret; }