From patchwork Wed Apr 17 08:53:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13633026 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2068.outbound.protection.outlook.com [40.107.237.68]) (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 1370C6A02E; Wed, 17 Apr 2024 08:54:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344077; cv=fail; b=rb4UlLPmQhmBk/PTvhf274qmQNfD7veQF/5KZEtcwgD9n1/Zw3wmT94SGXtCcqLXUEn/qTgnrX1ML6eDrg/jLZx7RWFRuYFyddpMNTKoGgMy2f5y3gyVv7yMUc3PGF1u4aEXSBE6fQoze5uQTdlsNZfLsd04HsOA5HU982Rw54w= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344077; c=relaxed/simple; bh=485yKaVzFw4bNDXfnNhUc4xLloZouKdblr9Y2t97zhk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ljR2t73DQQsjq8V/QvApbRxGocZ8n3n/3aZgjlM3n+g3d+xA36PeWdpAkByk4yONpWsNUjV3rA86xsUoGzCPr1qmnhpq/Rn1y8JCAXUMy9QPRMUvf8d+prWLIQW1eMYmln8eFq38v1qtLRfXS+h5BZFbhfVA/PxreZURfokSDhw= 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=Nu4LEpz5; arc=fail smtp.client-ip=40.107.237.68 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="Nu4LEpz5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jLs33OaX3yiohUobFYGjAqY9FvCbS4H25VOkm9mBTdPtDB9rBdEdBehBDHznI3UI+BxpAJhK1e0SGpCrMJpWWducizfPGNXKMVtvhmLOIk7MRW49Shzadzr6htYsblkF2wO3Iy+vojut/h9nUFjScjOiDO5TsxXMMj1oX56YefN9dIXS6aQfx+YGRwY9v/qj6ET1QR2MUjpbaHeq+O6Nin0LvmJyIY2lMd2wyGJZtVDI5/lJugqThhPJdmz/5AEKJOtR3brgOgtO5+ZWUzJZp6oizMYOx1wATTAt0j9Df97lPsDb/yC/K6I5hBFyDgH4QsHCWNROJWpUHmYJ7U5aCw== 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=KZCdGaV1dRBMR55AOAj+Gbnw8Y9WBD3ZhjqDkbBxAXTcotf5/h9sfyXb7rJ6hwdVd8ZHWnDi9xDTz9Iwplmmq1DSkkgXZi+IYLVYHMwcQtGpsC4QkPR6Y/uoDjiHO8deQsmg1Yo/Zw4iUiHJRcFp6eWDnCexjYN+Tb+ktJ74yVFmEBmAHvD42PE22DmiBhv3eMG/XVJFQPK2Gpe9n2PMMbB49Jf9y9SUr/W9nXglsuBw+lO1VNzG53CiZA5OnuURRyfoD8BloWK1uw39dOtGkight6aHzAKgTI+oUDdAqEYr0ndvSfMIbNpJbMNiKt6uJmGlrZQyyLM21MI9UJaVaA== 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=Nu4LEpz5wZZsUQej6F7yqOJ51W6J8x81KOvZOpfk8PAfyqpYTaOekqB27aaOsNOx9GZ9zBMpJ4Mzvnni3iyYf+eSOcVh324XQ4vAEzA/RFIAnd91nwLJPOwa2MIxFRxsDtzqII5gNzSJHFQyiALpOzFLcoDlvTBPuFzmwaI9VW8y3Jt5Kv+Fu4/Av9Jg5EazMpnR2Pr3nX1wST7YzP4ueR1F6waeR+UKlTqxSYEo1D1JqZX+NB87KYGHK8EXjFn2mOdDloqL6TihQB+7axdHFLjs8BaaIGMKQ1PoLTBOxSkFqZBohP3BN0/pKGB27A2uRwIqAba6kz/VAmb1jCBlLw== Received: from CH0PR03CA0408.namprd03.prod.outlook.com (2603:10b6:610:11b::9) by PH7PR12MB5999.namprd12.prod.outlook.com (2603:10b6:510:1db::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Wed, 17 Apr 2024 08:54:27 +0000 Received: from CH1PEPF0000AD74.namprd04.prod.outlook.com (2603:10b6:610:11b:cafe::d6) by CH0PR03CA0408.outlook.office365.com (2603:10b6:610:11b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.20 via Frontend Transport; Wed, 17 Apr 2024 08:54:26 +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 CH1PEPF0000AD74.mail.protection.outlook.com (10.167.244.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Wed, 17 Apr 2024 08:54:26 +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; Wed, 17 Apr 2024 01:54: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; Wed, 17 Apr 2024 01:54:06 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v3 01/10] ethtool: Add ethtool operation to write to a transceiver module EEPROM Date: Wed, 17 Apr 2024 11:53:38 +0300 Message-ID: <20240417085347.2836385-2-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240417085347.2836385-1-danieller@nvidia.com> References: <20240417085347.2836385-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: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD74:EE_|PH7PR12MB5999:EE_ X-MS-Office365-Filtering-Correlation-Id: dc9b5ee3-370a-4fb1-43eb-08dc5ebbfc8b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +7tV5ei3a74VW0m1t99vr/OxxE/ToQ506yaOqIPG/edBXaO8hGwQOhz2W4hTJQbW3ejlwa1qWg9mhemvWNssf2LPiVym/CSGm+icRh03n3Q91XB3LDIeIPtgX+WzWP6VhDLEFHrfYQx/TGxwMMDNKuL79UdfnxIL2EH22OUCyMF02IURkTSCq1eL4JEwo34Md5E1Sx98GbpGjhN+uD2YOCyTJ4WBtwFkpHnSo5UXRrD4pyEeBW7ozg31FyjqoR6790m17IlhL/sEdwP89l+wl2KgBHaEn2+nFRd3RU9RJ3EdqGcq326d4RBDSD9z+oD6V1VS/kKoGV2IFjMJiiFD//UKTAa+7oiwWqT0zvIoknWrlccOd5eQhSqtWqGYYaIpniKLWc8Ei+CaBmmwK2/pJBexOXI0VtlcAn0v5Krwhf5CUgLo+ZlXYUo6GtzFM+X1qINeQmyDCrnCO4tf9Ci0t5sVv2a1Ud1S7CFPVQraG183024UkibbcVjh8LYfXp/n25lkXpYys1TKZAGgUDVOXZMdDcUgOTd7+hNW3RxfKnBm+SIUHN8+weCVwacQ71T3T51C7prMe8Uopxs813X2HH4d8PkQwvhr8GjJQ5Rp7dHcrW0AC/DtyFL/VycjYEOOVrKzsoTGfMt0FAjrEneRlrLBjAjvupR9WOSWC6S6KRyDlzw/sHkYp0HP40myoT5yKu2RLrvG0vjiVZaLFrGMm4YtavztCxXg7x8sXho1/PmAbmxjU3US3Pj36GJjk9Zg 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)(1800799015)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 08:54:26.7085 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dc9b5ee3-370a-4fb1-43eb-08dc5ebbfc8b 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: CH1PEPF0000AD74.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5999 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 Wed Apr 17 08:53:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13633027 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2069.outbound.protection.outlook.com [40.107.95.69]) (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 6E8A712AAD9; Wed, 17 Apr 2024 08:54:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344078; cv=fail; b=E67O2MjAqPY5gkaSm/9MYOZh4k7bCLYUAk9PseCafCDEqlLlYp504+W0xUFNKe8WFfl16Qbj7w4PMhScuaPfU6LwtJM30YK1RmzgmvJIune464VrhfOgra76awgYio6CJsnQuCw++BUSd1FIFOYKSgt+jMzuFWAE5Hv1WKQmM2A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344078; 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=KUp6A2kWDHCvlbLzoOD8MHLPIyaprZXTuwcm9LrULpFvZFc+HvbvdcRO+H0F27LUmJS8DactqXaDn9qL7PfS3GKHcBKp0t2p/eyd7IcPg2BKwD84M2jSSal8/KTBvpwQLS97vK6uVHGWq4gTg64mHQ1AmlAoZVUsCumzhEy3lOU= 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=oS0AbGlO; arc=fail smtp.client-ip=40.107.95.69 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="oS0AbGlO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HPBrKF2tpma/hmgx5dTTksIu2N7cOw7+akh1ycn9f0mSn+jwnQExtZO66NrAUpFeTg4jUZF60jpHRF8ru7mTBHF5poESGbSSMVBYjwOz/v6gILudaLgHvmDGV4s1MVGN/wCN1W27gjy4vszHNepxRdYQqOIW36RM9+sjEO2ysh/rUtowzh+2Gr1G+ytkkfAluJY5gfYf1CHMGc7K5FmxdXdcoyu+PFAHIKNv7TlruJ3gpn3EvXA2qx3LBQofS2I8uNzRVcpM2fZKSh+iwZ2Z/7APw36N/laIe7Sf9/EDY/jw/dPwkerEl46B6EU6ocD4wYiu3XxFhXpaG/IWExO6mw== 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=TYzjESSnUWBmpgwH3mA4jP/ztPyD19ozNnkDvCb48Mf7Vj1keFKrXuTyKBzQvcfnTjBzx86+SzFlyuOoe6HKJT3AGS7wBTB6BTNIDY9t6IoWbDOenTvdAduI/kU48ej16X24R3YryoaCyiyo1AdA1fVQZ8/HktbCyOklvKcXslW4VTtUfjussKntCB56nlk02KWdr2T9J29TbTWs6ycITP9xAbQAHxl8iXMtPMuLpWwFg3gIY8MRX6riVf3SVr4QMsMgOtwAyauxILc9WXJBKbgm9O3IE7eZVXj7fBA4xMSqBGOfmV/IP72yrLM6quhlj6SUk63q0bHNVLL2ma8dDw== 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=oS0AbGlO46gpJgOJ3ANd7A+hohO5WaHY5HmS6BzktheWSo97l9r78bkuJBCOXVXqkvH3FFVNMK46g4WGuHDv6XMw/Ek9WgmbfXYo3ljF37XLIA5noZDTZ6/+0skKx+BUJe5Fuwxx33jHPe2r3Ja4KMn00EcOqdAF+hV9RC+dDvS8R1TChw3DDcuQdbC6xEnd58IXxQGGkc9gcaLqy8iR8FPGnQWyJ//7C4+3kyTKTb2RCNQAwSBGZviWPLD2KJi6EcM8yYrbHOFyhsCFwXI4QvrOpt4zkDJBHY7qEvl4qFFYzjknrsna5UU/vhxc/OHfYYJBoBH81cKbaE1yEUIMMg== Received: from CH2PR17CA0017.namprd17.prod.outlook.com (2603:10b6:610:53::27) by IA1PR12MB6212.namprd12.prod.outlook.com (2603:10b6:208:3e4::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Wed, 17 Apr 2024 08:54:33 +0000 Received: from CH1PEPF0000AD77.namprd04.prod.outlook.com (2603:10b6:610:53:cafe::fe) by CH2PR17CA0017.outlook.office365.com (2603:10b6:610:53::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.36 via Frontend Transport; Wed, 17 Apr 2024 08:54:32 +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 CH1PEPF0000AD77.mail.protection.outlook.com (10.167.244.55) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Wed, 17 Apr 2024 08:54:32 +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; Wed, 17 Apr 2024 01:54: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; Wed, 17 Apr 2024 01:54:12 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v3 02/10] mlxsw: Implement ethtool operation to write to a transceiver module EEPROM Date: Wed, 17 Apr 2024 11:53:39 +0300 Message-ID: <20240417085347.2836385-3-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240417085347.2836385-1-danieller@nvidia.com> References: <20240417085347.2836385-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: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD77:EE_|IA1PR12MB6212:EE_ X-MS-Office365-Filtering-Correlation-Id: 5065c9ab-a2cd-4c62-91cf-08dc5ebc0013 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ANHHXhiDf3qQ567JP2ZDuRhWXT7lIuIb/nlV0sNG3IIPaw827EV4VpJb8G1iOxM3Tbbx3rq903nc84QWHRJvn9S0lXKrTC3fvN67X/e1VR0wACQwG0uNK/ZemkitDA5yLMRY3prStq9hP2xSog6XlmrfbdZj8kzNBnPOr9z3fy62c8QiYuiBoyWsCILGUEPoI2IO30a7EjM+NpPeNtSzSQPiIK9lYqrVF65y2iVo0KUNow5xBXF4idR0rJvw4eK3eg3yg0flgFSAiXcpaualevxCskUxXIHm5jmL4dA2fYmLVL6lZxUtyR3U5JgbcEllqNeJbOCrpvPfkzNuONWBDd7IZYzhTy8LvL+/HwPlxYd9kxjK0w+ZyI3N/w1KJzniFcF8Y/wfOPBxnc9sxYYzvq6zA7E0erHR8++Wp1SDAW2+rxPn99pm1tZTFYGhItKFEMmYrq/oPlQlLh6O1aMKBUjQQ8hzzP3305d/wyRgrbXO+xdCQp+sYxdBCTxqpq6RnKH1kmPL/pQEwZMMyleUE3y1Dd18ZaIj1gBgyCoLqo2W4T7Mhs3aBskO4WkIYevBC4v5VUj28ANDwIhh9JSScSxoRzTgpZxU/z+xVEOzpZ7GQOUDQ2Z4I+6OPCxaDz0pbIIgN2160y5CHAbg5zFY6wz43lZrgkSfm+T4RGzfcF0Mvf9+zCtDrhHWgLNKdqm9qgxJ9LbglmgVFwqmPZZ8JQ4wQPWr89WQ2GPDTsNRV0ihIjWK0m3oiuh8I1+XxaL1 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)(376005)(82310400014)(7416005)(1800799015)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 08:54:32.6194 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5065c9ab-a2cd-4c62-91cf-08dc5ebc0013 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: CH1PEPF0000AD77.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6212 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 Wed Apr 17 08:53:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13633028 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.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 3DFB2131E24; Wed, 17 Apr 2024 08:54:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344082; cv=fail; b=PIYOpgvsH60C98vdAVUPIri5PoP8D1BQXZmwwBohiRNlyJyusQ7zDEndHzgxuROO9q0c7SKwUY/9MSsvQdgV3SVzyIi9+wgXkRCaHklNkEMclcDMhg/7N5DOpRMcW7AqX+jy8gnFzmkf6qdi5MPf0bBpfx1+RsS5Myw/PyOF7Uc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344082; c=relaxed/simple; bh=XcQ2R7YiJjsh7T/WxrW0Bm6pv+6NTzK2DqXe6ntFeqs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MxQN/SucdL8EwVFVhVBoVm0rfStfBVdx5kLrceNs+R2CxCRJ/DF4nlevQ2D0ldxqIs2M6tIGKPITjWr9FfkwhSQXVmjSX2AJDhQArroEhuEEirkVUs6T1yoVjPgn+aEHS2tLA+87AKYujBDCqj26V0h04WswZhqfN80Ic2q1JWQ= 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=OS89q2jl; arc=fail smtp.client-ip=40.107.236.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="OS89q2jl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SE84bVXqxj/DEuC0vOI5qnOmNxNhZeYaRr2D3IIjWJtsBsj4HfETbJyfMQdRACb0/mFWdxXIwQlNJJOB1RKhTO+wOJkhf0tMd20X73nPSY6F/QF5VJrnvz3KcmurYdETeRv9njJcExE2ZbpDqGQdagiBzugPa5yBJxmCd/5pC8T9Y0glrDwzaM15w2aYgZN2Ce/hmS7X5aTBrbPk6EUqyPH7I2dv7zzkUbSgdAuoz+801K2tfRU+CQyO1BVNbLKPUBkp19fZlR80hGwip4fr66ObPIsnXW4FKNXP/x8dyWyieheeUduftmuvT6UyfkIVHh+cOUoVXEWNTTPwlhvfww== 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=TOKeyAnXXbU/HfMxEm3QaatsOq+ET65o3EjyCOT7JIIl8Pl6DUm6TrNTSjPO0urZcK3zejP5y9TnlY+um1K2/KzISsiKv+nXQJwjrkfyc7IiXIhv/k8xJLP0FHgbpn1SNObKQV3DoK8UVWWn2bOVliuPVGIGL5HAEkZS2CsRN7v7VrXLtNxyU8+7+k/1EDjw79GAKQ9axKDr/QpO3mUQCuO+YdyLbDMs2XkuzHc2G9eh43DP1BBVS0s24iyiyKE/hcefuYJPKdEq6TPN6YZPpK4x7nNQ3eTdfPB8Gnrnbwz/APrGOH16IqSdB7lzgjCfHKT82MlYcq2pRpuYikUdmQ== 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=OS89q2jl4Ap2E0gpxSKsLxhsRyvTBgpGvhYhdeQuCN6nPAeINWv3nTCm5BhO1d12myLDMhN+stK01xrffH8PJEoXEIr+DiZXf+k8YAAJGQv/WqG770+m+A4gmwkJGirNLmXs9K0NNsxtyQezrYJSkg1TUFSRURMiI2zf2bXD4vH2oLkBhQc04n9CvUtJZlryCQI46SFnpiV2xzROhsYjw3VernGrcLFlYzCsOqAkyptH/v+4ICAcyEOyj0aDlW8OM280f9+xjtFaeWyP4MeugkpW+B/MZFSAfISVaqB6ZXuryoMUc65y3qsNzVKfc0Pyv69djIXJZXFAahKSsNC1zQ== Received: from DS7PR05CA0002.namprd05.prod.outlook.com (2603:10b6:5:3b9::7) by CY5PR12MB6599.namprd12.prod.outlook.com (2603:10b6:930:41::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Wed, 17 Apr 2024 08:54:36 +0000 Received: from DS1PEPF00017093.namprd03.prod.outlook.com (2603:10b6:5:3b9:cafe::cf) by DS7PR05CA0002.outlook.office365.com (2603:10b6:5:3b9::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.20 via Frontend Transport; Wed, 17 Apr 2024 08:54: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 DS1PEPF00017093.mail.protection.outlook.com (10.167.17.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Wed, 17 Apr 2024 08:54: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; Wed, 17 Apr 2024 01:54:25 -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; Wed, 17 Apr 2024 01:54:18 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v3 03/10] ethtool: Add an interface for flashing transceiver modules' firmware Date: Wed, 17 Apr 2024 11:53:40 +0300 Message-ID: <20240417085347.2836385-4-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240417085347.2836385-1-danieller@nvidia.com> References: <20240417085347.2836385-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: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017093:EE_|CY5PR12MB6599:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e90d5f5-4768-48ad-027d-08dc5ebc0204 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0XenUvnf7Iy6AxDcRVFbHv7qCNxO/QdfCmJICjxDpryZv5MlccPvAR1mXZ7v6qroYvTIkYMzvs5teRalGpGlzA0Fcn0tKij7LWzAvkvnrtxMeZwvsnillWrNzvbgLLDUTKM63X4rOoHfyA+QLnZ5BbS3f5Gpz5JZ7G8NPBuhY5ikqwze/CdYLUX8wcL3c+DsPlVOw0/ZyUKznHwDAvhAc7cniazUq/wzz4Dq7UcKX4W19vF7h5BJX0UX5jRsdsjEqT2FaCo+A8PTcyQho8XrSpLGFBP98yfRU1+aNcf+LMmb685dCM7clFqerlWktT/RUDGFKkv4VwQ8S7N4NUo8JzXFtyzJFuQHI9lUAElTqBHeV7FOae1lvMikPrcnpzTzBCJuBXx23SSfJ16bkrbps6edP/c78MIdPyQrX0XwENv3YgwIs4x4VM3J2v2lmVYyof/0hxJgzT1aCJGZfao9N8PsNLQi8cC1pITImjRFqBWGLQBUkkePpLpZEDqT4SIwmodyFVrQHGBTZZOTCS5JJa15SE0HP/rDEox3LUOfS4qVr69DlEFftnU4RI2BfgUvOgtSKPYwhXuezueTuNOTh0r1kmwUil7J+f7IUbNIh0l3QMwizHgJNCPuwepYEUBYjjO5wCYsgBc8SlA4l4jMkz8gxPJpQQjB84ajWZHzcfUGj5uy6bIvsGukZ5PNRZkCVvwrHaycSg6yhMXs8c7huKPdb97Kqfdb+FmiF2uPgpSJIHMyc8BeRCMCVQqLN2lh 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)(7416005)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 08:54:35.8885 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e90d5f5-4768-48ad-027d-08dc5ebc0204 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: DS1PEPF00017093.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6599 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 Wed Apr 17 08:53:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13633029 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2070.outbound.protection.outlook.com [40.107.93.70]) (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 20AD113A3EF; Wed, 17 Apr 2024 08:54:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344088; cv=fail; b=cMAtMuy4ddQnxECOwMckxRen7bsZheCgRByWqT0v08ctX9SIChBYqZGYOymUOUbHtJu+LU6vvSBcw1NIESSS+fz0IKv5WdqkC4J6w2gRi4OiXaRAPaGOd2cpX85rdbLBVEQ/hZfFV8atvH9Zs96/DYcjoXgGLudSsWgtXTT8lcI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344088; c=relaxed/simple; bh=OFdknu9ifl1dVUn93KjLhSo9144ESrNZYUFRA3j7NGY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YoznE7+ZV5PyD8iYR/Iz0ikIlalY+TzoxR3NsRnfxv7z46Ijt1aYula8VJtoxATX+UufFnPi/oOjrRHYLvW5To1UAFmlrf94lUQCW9RCsQ0Cqm90Zz28Kt8e+aubhytqaBQ5kDB9hfbo5eDUAewyxlTDb6IpSjrsz5cC4qLnWGA= 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=pVXmEzs9; arc=fail smtp.client-ip=40.107.93.70 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="pVXmEzs9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DiW6sDuo1TDA74vwjSNN7sGiYQIi/kR4cqhX0vq7HCAr5/LDIH1aiwtNQw0vzQHmWip1K8ozpfmMPiPI8ipT9x009ulETXzITNnVmXUaBjRmaP2OTuWvlKiOosOHckzua5pPLApTjDT0l7k1xJG+qf0juwLGPFW6h+EHpCMaBmKelWPNMpeJeENrXHxdZMttxxvojSzDAqVF4QpkLVy0QUBqhk5pIIzsZc8+rJ8TJRZTrro5Zilr3JZA6sPeSTRwq8SQLUQzS2FF+E22rj9dndKYZcWq/PoKFsm0/p0dSpNDUvsrGZuN8CKYxzn5ZZ7SSoN6BpUvwSIj+7aa0S9bbw== 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=QaLieoz21Rp9odGzegt6qfzYU1+/kw8dDp9NPy7iBq7W6kG/6HyBs6vZ3rf9IJ0VabzetfC/LqdnG7Bk21Nm+IcZGsSEHFt+2TUNFP0e5TZqzOt//lVqy+NTqx4l6+otSj6gIYwwqnWq1VXFVTUuBwN+8ShGB28lQETitC5VAX5jZFUjwbE2yhpAI43BypDUChyxn62yU5IKXGWTNgWvcCeOVz0TCoKFZkfsCuwXe66T2zvwwfKNZd9EIqFAnqd7j0l3OqxlwThYJVM9Q/pyR81cll6sz1PCocJG/XwP6axl86VtZXGCU4ReW/eCyOQRbjhoPeWGNDyjiVE3f2y2eA== 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=pVXmEzs9KNJy4DtAwpufdYfOmKBRD/HFiAHSoSAnirnqZ4oARa7lTZN5QR8azozJZ6N0Ap1dzygsXfUjuJrToaKrJZU7CGumLny7u750TmU2+4w4pCUjWj2vClaye9DcPvVn445EDZ6RvRrOuVBHkP4v8ZEz82Zl02RSo16pyRyNsnMXo1dobQ10CrKAxpCzfQZnDwfnNlpmBGVGr/QpZVFRKn4YLju8xNb+WYwdYyoD5ZXFxJ2a1va6RFG9Z/z9T5/D2wXOD0MEUfqp8q8Bl6fa5g6ih2tUkvE0aRFDWKBxZETf+Kr46UBhR3yYtaSGyy3XxXTHSNbpO/jlW25spw== Received: from CH5P223CA0005.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:1f3::17) by DM4PR12MB6448.namprd12.prod.outlook.com (2603:10b6:8:8a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.37; Wed, 17 Apr 2024 08:54:44 +0000 Received: from CH1PEPF0000AD7A.namprd04.prod.outlook.com (2603:10b6:610:1f3:cafe::3d) by CH5P223CA0005.outlook.office365.com (2603:10b6:610:1f3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.26 via Frontend Transport; Wed, 17 Apr 2024 08:54:44 +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 CH1PEPF0000AD7A.mail.protection.outlook.com (10.167.244.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Wed, 17 Apr 2024 08:54:44 +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; Wed, 17 Apr 2024 01:54:31 -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; Wed, 17 Apr 2024 01:54:25 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v3 04/10] ethtool: Add flashing transceiver modules' firmware notifications ability Date: Wed, 17 Apr 2024 11:53:41 +0300 Message-ID: <20240417085347.2836385-5-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240417085347.2836385-1-danieller@nvidia.com> References: <20240417085347.2836385-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: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD7A:EE_|DM4PR12MB6448:EE_ X-MS-Office365-Filtering-Correlation-Id: e2c5b927-946c-423d-a04a-08dc5ebc0726 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kdHpUfUSGwKiBgBEAB77okEc9FGhHqrdjcQZfyPltGCtDsTJrtjkasbomKwvh0ARjUYgzFsxmBhTodPOjtuFcuEyD/1F7UyD3vSZw6UbmrACs0ZlTF3hajlkInyEkDyrsm9HQSrUmXAepTSNoV5I/UlokfTNrkVwOOi8PFYNGTCeNxa/ZboJ4ggNBa5272587gNn1T+U3toVImPrU2JKKCI6K9ml9anhKNqDa79VDJYTbbAEsDLw2aqFmq8AR5iMoyO51llJh+77PULPNF8oKOMiNBY8T5x2T2D1KwbORyQfi4T5zyKJjbC1ts1TI1qMztEibxROdQHPR8918xrq/u4IDXOKeZaUlCa6w0ZH8frfqvNNqjxcuprPljzQzrbpMLlXfTt2kqUbIAHSum9GnF09o6Ngzz2tn8wTvOKjEzpdPA0apriQHcqO+JygMZKFc1gm4qc9fj6wK13aYmSxLb59ne2pxpt5MeVqRAWOq6tqB/rnlyaZjx6qx2kUZDc/htfJb2a2+NFYPiSI2l+XXi1icQsxUZ6NvV6P648KR9luERo6P8wCt0BgMPIzslgCpvy6cdkV/aLN4uqa0vTmclajhzBGEyOV7QcwCpdTg5D8Ugi7Hhw8k6D41teaNLUonHPRAV8XDJX9zKkA82aEXckEryIZAyh2z5SsdRnjc6BpJjRO2IwJMu9Oqk4avV1GFDFJxZU3vQwNeNF+wpSGenVh9zM3eFeMBiOx2Ze6kZ9II6GZ+j2wthNdvDAt6YB3 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: 17 Apr 2024 08:54:44.5039 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e2c5b927-946c-423d-a04a-08dc5ebc0726 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: CH1PEPF0000AD7A.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6448 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 Wed Apr 17 08:53:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13633030 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2089.outbound.protection.outlook.com [40.107.244.89]) (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 F017913AD15; Wed, 17 Apr 2024 08:54:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344094; cv=fail; b=C/BQF/JcdlrkOG0ZmhLwzIappSGQt0hOGYH27HuciUzohSIKcAMu/zjlKIvHHNjrds6XAMx2rYuHxA2ZiqEg887oVLAkOtyOpZqPF5auFqchNogy1GIRCoygYNteHakNrzstdjJtWwsgHLrJ1zNS0XdOm/5r6ITFcX/LwzcQmiU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344094; c=relaxed/simple; bh=QyEJTv+ju1WUuRomf/6VJUg5R13KnCo2VxHBZutDlq4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k7mCjfV+uwnhbuchFnrfRMsMlzLe08cGQ0SAfBWgXq0l6UzIMnk2L7QpX3ypU9rOFA50YlgcZ1qIuQVA6cErabA1UydHulxAXpN6/Z3iRBeBgtHLjWO4NhBHzTJz3lQkPi/Ka55dWxohjP1raSAtGDXByrGwIBdu010yXO7UGbo= 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=Z6PxIzDy; arc=fail smtp.client-ip=40.107.244.89 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="Z6PxIzDy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FteMxxS0TJqKly+wie098FbUR1fyXgB54XqvqYrBDWh7wtedy31luS0OLNaOfvFZQAud6gU3RiN1gUdLdF3Z2Q8dI5Wy99IbG1jm6GWIRtv+haorTz5NfNSpYda1IJ8pDir/FcZ2bSWHM89ZFe+iwxStyXNAjBlW0FX8iFCVI/mWiZKI+VvbrHS5DPXrKvdHwSACKCBDuAdDXFR0KZWWJbtFabD0aHJid6MxY1dhF7TCfbo6FD0/x/dzXvwQxDCrg6JelMIWI5RaEsjlo7e2tVTBb2k92mnh3HwnLhBH6D159WVMfvAPhl8M6Lr2I4VKLDnQ07WC8a2xsax1VO0brA== 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=BlpbBJ/hgJegJ2kX66zncWMPgvxImYVPYadk+WHNMR0FWNeSOjxWfMtBRaNWGl7xoyqJvFSgRwwiEjoCcX3RUfB+fSGKzuXhvD5g+F2sDKR2T8b9eT+egjvcvmnA+CwYXxeaElM5zl3/APsIAuXVtc1sOFUC9uR94YEY8nJEaYL2HtFXnHeBbGyw+mwmpM4tFjtPQnRZbYYjEmootWB3156gWvvb7/pzvyjAA9Obs3NqTbML9C+uMleqhZ5mKSKJ3KcUvo2kNLFtMhPutvjmJjr6qqbRnerX/cLUCx86FwvCW0HZxgjpTrvY8haISymksEovHTSt+ZpWWEyQSDd4FA== 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=Z6PxIzDyxzUHbUIc9XF31X4qRS4T+cW0sfd9BGuhwxCdCRvXBrJKzPvSGgqku4nKRjnOZE20XvnbK7JCPlcyXsEWRnutFtOZV4lRa2dZt+NuTRQggxzwu0uw8EtGuLxIDmLPSE20gUfuU07PLWq7VWq3IEZU3bGpoGL64JpdxP6f0tmn/YSCvrQTO4sgnQZdTGVIAwp3oIA+6TDFRYoCWdDNCP5/PAjIARaHtat2v2BMjCHYZesOmvSsMBxo+FVjK2+HTLuQ+SfkmgvQOG7W5Y5q9G24AYdqDhtI+ewyzsWQGfYP7tFwLt+kumM7cCkwN1dHKcy0ZdPHM1mV3kamdQ== Received: from CH2PR17CA0015.namprd17.prod.outlook.com (2603:10b6:610:53::25) by PH0PR12MB8050.namprd12.prod.outlook.com (2603:10b6:510:26e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Wed, 17 Apr 2024 08:54:50 +0000 Received: from CH1PEPF0000AD77.namprd04.prod.outlook.com (2603:10b6:610:53:cafe::6e) by CH2PR17CA0015.outlook.office365.com (2603:10b6:610:53::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.36 via Frontend Transport; Wed, 17 Apr 2024 08:54:50 +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 CH1PEPF0000AD77.mail.protection.outlook.com (10.167.244.55) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Wed, 17 Apr 2024 08:54:50 +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; Wed, 17 Apr 2024 01:54:37 -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; Wed, 17 Apr 2024 01:54:31 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v3 05/10] include: netdevice: Add module firmware flashing in progress flag to net_device Date: Wed, 17 Apr 2024 11:53:42 +0300 Message-ID: <20240417085347.2836385-6-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240417085347.2836385-1-danieller@nvidia.com> References: <20240417085347.2836385-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: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD77:EE_|PH0PR12MB8050:EE_ X-MS-Office365-Filtering-Correlation-Id: d9060071-20d9-4229-b675-08dc5ebc0a99 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qdzfZUs7Q8FgIq1TmHbe1PXm+HgNa5t+0ZZ5uFwIQ7cpes97o/ewtMZGqQzcRXpzSJDgAOekCqTA/iU3CpCW0PdUDK7fW0CCWQin5Xe/kq8FrZgITZ5Z3raNIBnDAoERwtTmOR2dVxep3AQddcaYRD5PB+rfnsb4SC47nrxzlVIm2uGhhfWz8WYxnEZqj3UHAc5upLaGL/uFfdmf2fVpMIjv+R14lirhD+jnq1bU3JkjrOISpg0Ka85ZUQmGpUozLsmjTMnPwqCEaqdA2qbzSB5fsmRpci2AwbCeWu/85CaMienqEkGAqQKRk+mIAJPCOtMnycWQUhrNafWoxDGV3QVXxAaDm6IBD+QYkwPvr2fiPyrApzUGqQdvs6BG9WmVpWo4xpuFQDaP+S33Sp99i/flCs2WU5qHJoWhRGw9Z9Og0gA4hHufnNc7a9/gbpI8umcOwmCQbxK6cmWdWdG0nKQXfpFloB5FooqeCfMxC6XVKxm25RiUlwNP6pFYU6hT44Zg4tSgQdCIfyXbskCuVSMN0d0zgmSUxXaokkdkWkBNo5xpHxZO2FUDLSps21yK9yhPC5FQdEN5/XG1kk8zRRurJ+WVWsxAgdawXWicF3cF3ZwESKDsHT+4LYXL+BIRtUj5qaEZJWMV9iSlEHn38pRcqGkeM86LK2WJ8EaXJSmf+R/sJHHlsZqa3FtmVOVZg7ktLfwGBpMT8x2k+0eAEOaMwrD9tJfkUPU1KFJI44nZ8mjLtDgydH/s/vMyahB0 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)(376005)(82310400014)(1800799015)(36860700004)(7416005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 08:54:50.2757 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d9060071-20d9-4229-b675-08dc5ebc0a99 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: CH1PEPF0000AD77.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8050 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 Wed Apr 17 08:53:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13633031 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2057.outbound.protection.outlook.com [40.107.100.57]) (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 0418713C3D8; Wed, 17 Apr 2024 08:54:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344100; cv=fail; b=af1V8iFsFEtCxTV0n+r4K79TTgQnVRE7MKpu2WkFBDfn9MZg2cYxPruK2h46FMLL081jQh0OGSiQ36te3uXcVXhimsItId5Vp/5+x9oUiNg2p7eSSjDeYuXNOw7OPIDBrxVicWKoNx1Z/i9jYHN9uH+WYgIs1v2RcvcZFVpKytc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344100; c=relaxed/simple; bh=SdR8AK9p5eXkXVsxuQJGJMTlfnSMm8NrhQSC3qadvTo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OezLtNk5P5qu9PS+iP4xO81QxHyDGDv7Qw2h9Ykpi7jDv02WXISXt6nXRku7rPwkOVfKxbWgL3eAU4Kp6Q3PpVEIui6cEt9cNbUvj+OwoBWRDd+nSZFOFiGgr7tIMtXYGukygPpKVijLbHd7qeR4LC0tmmmeQ9vnjPr16qoBNdI= 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=iBYYDi5w; arc=fail smtp.client-ip=40.107.100.57 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="iBYYDi5w" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KF3Z6I7riyhguSs8dm4z6EX9FuKgY4LMRlol/ZrYmwp090kwU1goiZaeyXkdXHkH2sGInMsXL/UdrJRQH0pb7n06YTfS6rDzvtufSIPB0UBCbMJpd6eyGd5ASRNSHb/nfrhj0ut2qxAWJeFuJ3OubwWEnhX2LgkuztZr6aEy3UsSwFyG3XRIPWBH5yXP20x13nML3EHBeim7v+pY6rZCJzhAoNL74Bq7PFeAv6Gsv3+8tv7fpxKHLCVtd8YDXyh3I9crYoONlk+2+KsddZ2kc9CTezgVtO71oRm+rkCH4pA3HWE0zEue+nNRv9pFPKT5BZ/YbNcAz/d3CVriYytMJg== 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=WOupUmA/PbZZM2Jl4j6d/P5H/ZYdBczDizmo6507Qsv4w5j+T+useDdWSIGDIn4aXdi0HDac4gyOCOzTJEdKK0OKtxMUB1Bk/l8RxWxc8ZpSJlZ63f8ho5AB60ixF2vqnugoZpH7DDuqzUd5njoQ1z8yCkJZfBMp3HMpP+PXMnF7rkEZyNfiEEDSAFguaNbhugH/Q97ADHWlXMPj1zcQ8dQb5vKXYN4Yu3mRankUFg6UOWP8CuIBw7YN8SVFLyZg95s0k5Ygfy+lJhxUK/bgNBZjq06w1em4jPAfaEeg3Z6aPdkLkUXE4xmeo6k/CRzM3w0w+27rs8MbrWnnhwCZWQ== 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=iBYYDi5w3G5GNfQGgLQsQvv2ihdumW3xHVm62dwEyRdkhx8oi9dZ4qLAQgFF8TdYW/4JeRaxB/cesIIlaDzm8GJbabgMWAT3uc6PMoiMhSblgTiITidKgfZCbvhjSrBvrm4qb6UGR0K1uiW8Q6Y+gQeu2irybrxbN1/GP1Xh+1/VGeWs+zpyuxsrzOYpWJDpN7Rm7Td6jaPmBFigrk4jsGCLhJaTfaD9GSYZl4desOUCQtSmnoAegq36b5nVjEsGyd6bZGHbXugoaELqv8mljeP1tS/vI+PnVhY5eVy0R1fNpKgbkfz6bLJ3Z/FPjpSTtqOceH+AaL919DVixMk1Eg== Received: from DS7PR06CA0053.namprd06.prod.outlook.com (2603:10b6:8:54::8) by PH8PR12MB7026.namprd12.prod.outlook.com (2603:10b6:510:1bd::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Wed, 17 Apr 2024 08:54:55 +0000 Received: from DS1PEPF00017092.namprd03.prod.outlook.com (2603:10b6:8:54:cafe::b3) by DS7PR06CA0053.outlook.office365.com (2603:10b6:8:54::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.33 via Frontend Transport; Wed, 17 Apr 2024 08:54:55 +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 DS1PEPF00017092.mail.protection.outlook.com (10.167.17.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Wed, 17 Apr 2024 08:54:55 +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; Wed, 17 Apr 2024 01:54:43 -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; Wed, 17 Apr 2024 01:54:37 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v3 06/10] net: sfp: Add more extended compliance codes Date: Wed, 17 Apr 2024 11:53:43 +0300 Message-ID: <20240417085347.2836385-7-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240417085347.2836385-1-danieller@nvidia.com> References: <20240417085347.2836385-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: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017092:EE_|PH8PR12MB7026:EE_ X-MS-Office365-Filtering-Correlation-Id: 4707ea47-76b6-488d-e65e-08dc5ebc0d98 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2gsZGOPyzlkL88jt+jI1OvmIdCTvvdcXM8d4PebKMkCRnnbwB6mjvseIGtRXsvOUtzLPwy/jWoMuuDDfWUGuPE638EDMZE2pic3tT5ur7oXTPCtNqhp4M8Zmu/G5LyrxdutMPvkvgEQ4pVvGQX9tL8PbPW8IGJ9q8yReW/gk2dA+OTWRoNsrDASUL092MZbRkgmeGMSwCdPUrYmgSMW7bwt/pHi801qMdrqkDaNjX3NfvTE4y0NdHorclz7zUMYSbuRC9UNxq2HqWrWC/QjgG+ev15Oi5X7NxSmLk/xsW2fOQec1Ghh1QWku0g+4SxVRIKGyiS5q3M+RySgJKQhqILhwE+1WQfqtRkHOwiC28Fw/iO1JDPm5zeG3h2b3lvNrBDv93gRXwdK9I4Ps0Xw6JSMa+wCnKhUuluuyvasnVIljgncKD4x/FXR7TI3jTCXyhjkYrNnKK8ujHdi83T6op1a3kHp5jpg01E4CY522bAz46je1+2PLCFyBEcFGf5OHdl6Yrp/A72EsKoZLY9sg6ZNUkZr67JxUHvIpI9iaFiB4s0EZMlcfczhatXyxSnUeCdYsHQ11whaBawuPvyJRipLzhI2/QAT9mmkJFMwyQCuleW+tFSA95+g7OFfYb3xWFQJKFlpTH6nKhFwqB/6q3Fd45sACaBr4wvFqTTsvsIop2YkyIi56C7gK3D7NoV5VMkRnwBprpelT76c1JoVwlgENmjLFMlmpAjtPM4xzR9kIthdMaxx5szm5EsYJ3KtI 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)(1800799015)(376005)(82310400014)(36860700004)(7416005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 08:54:55.3192 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4707ea47-76b6-488d-e65e-08dc5ebc0d98 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: DS1PEPF00017092.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7026 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 Wed Apr 17 08:53:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13633032 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2066.outbound.protection.outlook.com [40.107.101.66]) (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 632E712F59A; Wed, 17 Apr 2024 08:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344108; cv=fail; b=rFeXi4H1HGztZYydZiTPphcE3ibuT7Oho/khqWuP0i1Gt765GS/lyLswbGnM+C0UyLq9CKdtxo1/+7zstxJ9rmTv1RQ95vB5YmvcimUVW6wl/52voRJ5I4S+UX3HWJzVXHNNvNIBKDNX5v2qZT/k9cRVZY7IRvSPyFa5VUrcX4U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344108; c=relaxed/simple; bh=wXxwInOkYOBeU18RXzGLzVvNX7ivZL+cMqA7by7YNh4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hlwArqvH0yEiVngmFtnsTBrbXnq6huEgHgpIAjzI8SyzNGcgQfwLi0WZQY6Y/EcZ1EfL/+HccZy1Sh/Mz54FVOt5hcr6IMBchgoFet1mJv7ZROM1m9Paifw8k4v6SE2Kabf7uuXFWVqDUb/jfzYMZumtfIzprXlg8UfolPdzXFU= 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=b4ZxezdJ; arc=fail smtp.client-ip=40.107.101.66 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="b4ZxezdJ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=atHbnvcPBysHDHnWY2M1lBD8QyrbomlHg5oeH55yZ+UuXOj9+RU56EZyogi1q45j4H4hYQA2uceDJkAbbN33MQ/aTWF0yt+okMN/4s9RBfZuDy9lY24LT9gKuEebskerUELtw75cXz4pSr0PNHaJ/0N4Yh8Gty270uPuBt8Jb8dv4NO8G1kgPYOIyt8bpkIEtVBBrn6+Tdbl0vRhHdaa7jqT6Th3pdnYFzbN+4Pn9mRvz/8X2xqZ8zewJ9avrZcGlBaQALcZRF44yi1U4Z6Tkvtrp85ySmhGTUoWo6VeZkbqt+aXZOUEHXScIBnHEfI4RDJ2XM1RIHlsSYNsLzAytA== 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=RHzeOBq7lQbgLrjb9+EP/kFB6Tw2/RhiifxWwYqa4GY=; b=ilEizmPTEpuUyTW1jRTdy2r7/bcVpzilNhNkaPuApAtQfj9EiRghMXxhSLMzAef3T8pgFliYRFhML/xva+vQTY/noKaBzK1iobBBmUI7Plhz1bPbM/Qd/RpWjSgGZMOj0wPqRXT/Cui6TbSZ8DyLcFIYqGAhyJVjoySKD/ZbHhk17mTpNWWJPwuN/rrR5f3rXoXeMSgw6KDqbFWiBhQAtgawW0rn44zW5bLgTkYq8UBSbZPHB4pBJz4vo5/nFDZYynX04mLkHYLqzPl1Y6/K0yVlcRJ8+FLylWO0ASbGftZPLvmbGk7FTMC/5dfCB9vNCUqvjQw9wJh9y87mqSP03Q== 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=RHzeOBq7lQbgLrjb9+EP/kFB6Tw2/RhiifxWwYqa4GY=; b=b4ZxezdJn9i3DYkJZ0+8/4SpkyiC83HR6CSl8cd/hecVOEVOdMUEFjyKPk6AEiUgkfTRKoIqrYM2EFwFdcO331WpFrGMG4lyYiD/aPxE6DonFBZOtrcImLcUXcEq5jx/nSa3EI739GOYL5wTga3ILzwO6GoV2idgZt8SKhVBCFebfBqgu5on3lndq4u7nQpMUp7bBrLqdYTD3cI1zO7DpkHOpK6gOdsEtm+tRq/YfN8jBNKP/dKIXXHYMF+bEZD7TO8FAzrClAJ2EI5Y3r8JSyEe9+toEj0XNJdXc7rbw5r5SOV2s/JHC7xQ2nodfCK6H0Z9NwTLqa6KkHh57TeLxQ== Received: from CH5P220CA0017.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1ef::8) by IA1PR12MB6434.namprd12.prod.outlook.com (2603:10b6:208:3ae::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.49; Wed, 17 Apr 2024 08:55:02 +0000 Received: from CH1PEPF0000AD78.namprd04.prod.outlook.com (2603:10b6:610:1ef:cafe::18) by CH5P220CA0017.outlook.office365.com (2603:10b6:610:1ef::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.20 via Frontend Transport; Wed, 17 Apr 2024 08:55:02 +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 CH1PEPF0000AD78.mail.protection.outlook.com (10.167.244.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Wed, 17 Apr 2024 08:55:02 +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; Wed, 17 Apr 2024 01:54:49 -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; Wed, 17 Apr 2024 01:54:43 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v3 07/10] ethtool: cmis_cdb: Add a layer for supporting CDB commands Date: Wed, 17 Apr 2024 11:53:44 +0300 Message-ID: <20240417085347.2836385-8-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240417085347.2836385-1-danieller@nvidia.com> References: <20240417085347.2836385-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: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD78:EE_|IA1PR12MB6434:EE_ X-MS-Office365-Filtering-Correlation-Id: c819ca91-da2b-4b55-7f34-08dc5ebc11da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dfbUuGNiGCdY8cIP3+YNxybDbHmr0oL+fz4kHeHoFIbve20bxYvImORIPUSMmryChdR6CbWMnTCJTRD17EaOFfwmk5oNx98riPmx2VIesud96yLw7kTjJsOBtp24KOWCsyc2R2IMQseeELM2hoZErhXiKAfriIV6IHUCTnMrR+2QTjEV8LfzcOecnGtYJDR4cV4waKGXUa2gJN51jSEsXDXSCmLrqRV3kkiChJTxa1NpRkkK2uheWcQGxVxAYlZCGVleIXQGbaei5QmybyVmRCOFKNrFcjyR9x/fPwgs5u2KrXvg/oEuHrq0aKzno1EbijTxfsKNoaGLw+9DSL5Ht53D5rSVMkSy9XKfpM5l/R2GKbmWSR3YKoRySPFN1WNmUUioitxaeE8x5AvdFWhAQo2feY+z38EpWuhe1VN4H4hIDNXty69Ex9Ez1HWjuyCKEcbCQjaNqx/n66EgAvXIodXqsjbC2uPZKm+Vh48SXjyqyfUNf0PY51+hElxYbXaniq6i/GmmQXBy38PMHMiACrjs3mIh/bBKbLABuTG3vxJdZe3/qPbBKNHkveHYdUMSFKfVBaJ9e3FsQjsqnUxDiECgnD7XmrTpM0xGUSV0CDI5nddMJU9o445C83azdLqUTlVebq6HSut19N+pWDooDnsh+P5u3sgGXIPhp7e3tJKTFDi9WXdAjrda19yydDQIFIJoJmtXR2S5/KHIew8pBog968NmAJ6SMBxsVXa7gNkZaTaXxfY4W9Pf5v9Wotxo 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)(82310400014)(36860700004)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 08:55:02.4599 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c819ca91-da2b-4b55-7f34-08dc5ebc11da 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: CH1PEPF0000AD78.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6434 X-Patchwork-Delegate: kuba@kernel.org 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: v3: * Use kmemdup() instead of kmalloc+memcpy. v2: * Define ethtool_cmis_cdb_request::epl_len to be __be16 instead of u16. net/ethtool/Makefile | 2 +- net/ethtool/cmis.h | 114 ++++++++ net/ethtool/cmis_cdb.c | 579 ++++++++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 10 + 4 files changed, 704 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..433063db7bfa --- /dev/null +++ b/net/ethtool/cmis_cdb.c @@ -0,0 +1,579 @@ +// 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 = kmemdup(data, page_data->length, GFP_KERNEL); + if (!page_data->data) + return -ENOMEM; + + err = ops->set_module_eeprom_by_page(dev, page_data, &extack); + if (err < 0) { + if (extack._msg) + netdev_err(dev, "%s\n", extack._msg); + } + + kfree(page_data->data); + return err; +} + +static u8 cmis_cdb_calc_checksum(const void *data, size_t size) +{ + const u8 *bytes = (const u8 *)data; + u8 checksum = 0; + + for (size_t i = 0; i < size; i++) + checksum += bytes[i]; + + return ~checksum; +} + +#define CMIS_CDB_CMD_ID_OFFSET 0x80 + +int ethtool_cmis_cdb_execute_cmd(struct net_device *dev, + struct ethtool_cmis_cdb_cmd_args *args) +{ + struct ethtool_module_eeprom page_data = {}; + u32 offset; + int err; + + args->req.chk_code = + cmis_cdb_calc_checksum(&args->req, sizeof(args->req)); + + if (args->req.lpl_len > args->read_write_len_ext) { + args->err_msg = "LPL length is longer than CDB read write length extension allows"; + return -EINVAL; + } + + /* According to the CMIS standard, there are two options to trigger the + * CDB commands. The default option is triggering the command by writing + * the CMDID bytes. Therefore, the command will be split to 2 calls: + * First, with everything except the CMDID field and then the CMDID + * field. + */ + offset = CMIS_CDB_CMD_ID_OFFSET + + offsetof(struct ethtool_cmis_cdb_request, body); + err = __ethtool_cmis_cdb_execute_cmd(dev, &page_data, + ETHTOOL_CMIS_CDB_CMD_PAGE, offset, + sizeof(args->req.body), + &args->req.body); + if (err < 0) + return err; + + offset = CMIS_CDB_CMD_ID_OFFSET + + offsetof(struct ethtool_cmis_cdb_request, id); + err = __ethtool_cmis_cdb_execute_cmd(dev, &page_data, + ETHTOOL_CMIS_CDB_CMD_PAGE, offset, + sizeof(args->req.id), + &args->req.id); + if (err < 0) + return err; + + err = cmis_cdb_wait_for_completion(dev, args); + if (err < 0) + return err; + + err = cmis_cdb_wait_for_status(dev, args); + if (err < 0) + return err; + + return cmis_cdb_process_reply(dev, &page_data, args); +} diff --git a/net/ethtool/module_fw.h b/net/ethtool/module_fw.h index 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 Wed Apr 17 08:53:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13633033 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2073.outbound.protection.outlook.com [40.107.93.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B8EE13C680; Wed, 17 Apr 2024 08:55:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344112; cv=fail; b=hrmX4iy8ThOzcAEIOs2VA1aPbu9e1dm8umaR/vNPNNh6R81IqjEaIuk/7UpzX14D2PrPIidzcFqmgQ5HEcsSHTPUj0nEVVW71UFsos0uURQxOpBi/1vOGPMq/eS6pZWnYQw2gcHuuHlbA8qLcE6yxN6crAS59OnVek29t9luPnI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344112; 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=YvzhgZ+dUQo++kQL/uaUl5CtGgAZnzbByzJyFckyoTdGQ+lwct9sQ5itD0eEe2mY20nuhKf4IsIky4cxCZDGwnmSo/FhypKloYMhT0ngSxVSvaCRYjnVmEaJiNcIdEYU2ooQleolEzra5INt9oTayZfIyyWVEFyHum6GIjQNcLw= 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=D6CPgP/t; arc=fail smtp.client-ip=40.107.93.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="D6CPgP/t" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D6MHvmkOB9eCYZ9LsapejEVfY8p4UmIvekA/0aq6ppDyfC3HuKBCocq0cAlaQnMN1j5p9lHE5R11wkCky7Rs+SQvSd8jSTOftLMOEFlwWaWdAf/whTbPzkaD1Hz2OVKlYtaSSpT1DR1V+zg8qncOnlRQ2mg0GAX/0qrIADurZMiHyWtj53SQRx/U6ORAXU8ocV0W+iZm5VRs2TsBHOwHMy3SZ0QEVTqy/JcgTo0DXy5ph1d149msUJ0rvRgxa6mBdAW2kPqOO8AMSm3PI2KVpplBlTtOb0OpGsl4cr/qOSjlw39OVkfRVXn+xQrLaHBGpyt3DJ3LrZ4aGojT8RlCGQ== 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=dYDv3igHDzUgt3a9LR6Ca1JtMzqPLC3Tus4ezH+/koMobDhEfhalkisXVlBEsVqVF5EdKdLofI7t/+cmBl/0FWxDY0n24aRdufPVPZ+DGUD4cZPcKYJtzu0uptcsr0YmNzjxr0jJ8hGe5sv3JtLtl30YauyWDkGJWr6mu7/sMBSwLi57qm3mmUNWw/dMKxrnt38pG5voOE1k2prs01nr0VXvXFimyzqu0pYBi1JeH1QPQ/FpMxCpRKN0t3faY8bAXWN+fJ7Wkbw0PU37J/gulJ5cNki61RfjNYyB5B7K7WsELQxpx6QvuE9bK0zBBbVUJrSXkIvWqTF/XjnIhRTqGA== 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=D6CPgP/tevlTzL5zA4OTssCzUMIZgNPJqf8WgcFjq9DIHwXEoift+qFzPyGK7eN6HKVfyaLNjHwHUWemink4uv1wKoufb/CULNIBisUgD/miSR19q/APBSyEUknJqR3a0YsgEY69xjDUBkEiWxPXYVz5ZNav1K8DjL4HNqBx/CyYqfTBz6GJlP10T1lt38dKbyj0ToBfXtFDyO6dmlgKlSYJbMAxo2gUotEznyqQCTyiI66dnGKqR2GO4GV5q0uCJ7GA06QVW8MyhULaA5whex1dEWwX+0yvblITSCoXKfystE7dyn9rUwubrDT+t8TjWvVkX7q8yiYXzXa273CQyA== Received: from DM6PR07CA0076.namprd07.prod.outlook.com (2603:10b6:5:337::9) by SA0PR12MB4432.namprd12.prod.outlook.com (2603:10b6:806:98::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Wed, 17 Apr 2024 08:55:07 +0000 Received: from DS1PEPF00017091.namprd03.prod.outlook.com (2603:10b6:5:337:cafe::8) by DM6PR07CA0076.outlook.office365.com (2603:10b6:5:337::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.24 via Frontend Transport; Wed, 17 Apr 2024 08:55: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 DS1PEPF00017091.mail.protection.outlook.com (10.167.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Wed, 17 Apr 2024 08:55: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; Wed, 17 Apr 2024 01:54:55 -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; Wed, 17 Apr 2024 01:54:49 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v3 08/10] ethtool: cmis_fw_update: add a layer for supporting firmware update using CDB Date: Wed, 17 Apr 2024 11:53:45 +0300 Message-ID: <20240417085347.2836385-9-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240417085347.2836385-1-danieller@nvidia.com> References: <20240417085347.2836385-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: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017091:EE_|SA0PR12MB4432:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d42cb42-b7e0-40cf-d17c-08dc5ebc1488 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Z9t0UPbwrERcoFFXFuTwDjSqCNRJhRTOYgVpQkFIAnil2J7kO3v9ukw4mxiptqjxci69EPxQai9h4zlXhDH1BTE+zLSv4EBN3bpTFq+dFoMfSy2JDjqzKRYI6HmGYVj/dO6TclvEfODDXjaaL6nLnVyB9S7ml6Dt/dnEBAfmizryLA6HtIsvOY6tnvF0AuhXlJDZ2WmFVUEcHpTcl0qxuP9dg2klWshb6OdjlNLZ7Pel/z04eVi9kAawFsRpSlByAKq5x7pr/SOCgs1FFnWQ06iyKOqN3ZHtjJQTksNJ2C/N9QiFNBwNH+bShvj8NCS5CKWTqFeXlIPzruheBRe0ech7KEtlr+5ixHA24NplfMebH2LVLUYUdQi1tJ9nAPF+op1hqaLQ1/1PoVN+VrpfmPkLPFQFocC9asXB98YwRvijpN4yzOCW5vUvpY5R0JBoBo9TRjD7MXwmfEVJVcmTIaZMWUYtrwmtzWEcAzh1OeicEePH+OjvKkolKUsP7vAcwBeTweROURZqJOG/oxRXtK0DHUpm9lag0Spwez24TOR8l2DP4LSxKTvwcoJ2Nn2QAvoD+s47FF/v0CTLfJ2EXgoUH6gQTWf1QBFwNm9XRYW8hPm3KKoPeudZI0Ah4kvAHjL7+2oqKp+lI6MqE7LnuZrwEN5oekCMO3oIcIv0ZWcrooBEPozuLkFJEFft12eEe24+nxMDRqzPX3zHjIpgNNDq3GkGNp/JoQceui7VRYIX1XPHdt3sDVIoLOVDSc1Q 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)(82310400014)(7416005)(1800799015)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 08:55:06.9578 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6d42cb42-b7e0-40cf-d17c-08dc5ebc1488 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: DS1PEPF00017091.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4432 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 Wed Apr 17 08:53:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13633034 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2046.outbound.protection.outlook.com [40.107.92.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 D009A13C68F; Wed, 17 Apr 2024 08:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344114; cv=fail; b=GC9xzVC3ILlPL6UybkGKLu8v8cyNXDw2DUrfKvzE1C8Taaxkw3tQhUiguoIyVNosSGPeT+Gl+qQOrow8DgJlesL4Kx7JvXZlRn6PcRYI26/Rz+lFiOArCIvD2LqYZnsKyik4InEKrrO/jRgvSat7r0v0S6/NjhCGEbFOOyV3Tl8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344114; c=relaxed/simple; bh=AfMSgWSQr14Kq7RRN+mCLxiDZzv7bYqh+EGqO3emaZE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k8p5wKIP0cyb+b21mPfw028tZYFH9p5q6BNYf2y/5W25p0CE0PMrCKirFOtGOqcEluQKTWrV4ine5tj0rYs08/R1dbHZfNq8QI/EKZ+PrHjdiSSR/WtfjAwX6lDIRnoJOMm/f9gyXk75qmbqh+tIwy31ZBfH4vMJ4EA95OkVI5o= 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=nwjekkMu; arc=fail smtp.client-ip=40.107.92.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="nwjekkMu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FRbE/wOvj6ultxaGaasZ14lnvQOKyQxBTsF61H9bE6wG9TUj3i4iJSxdvhNmY39tPNi5DxAC2ZDiOfOrIRAhLIdF/GAFul/OY6lWhehNlvCJ6OV8bi8iNXeO8g5wfeVlCq5suGUy2nvl3NIe99ktYk9sonvP1UFI9+m0oley4r8+eFnAvApz7CAejocHkGaV8Dbh5y0bxJ/g6jPaVOidiVaaIMzEk3D0Wqe0Q3+y7HEeu4pUSo34h1Y6E0DXdSYlsQTUlifBmknM8ysZ5rH0Uzc9EAhsryhk/VevcUudqN/iOwmUnG3F8ZQ0H5+8kC2k6npE32mfPrU+7+Vr+zIPyQ== 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=P1xGKjepoa/KgooQaK7BjXsJ3XuPQPWTLOuSdY263YXh90s2e0DLkixrf8f1QHbq6sHulSWREHBEgl3FKCQ3K9JCOOsIrtf5hjV/8UghnQ5YkieptqwAVdWpKOnLiP7btMyFhbRHhxtzluhWZ8xgcjBd+shXzkki3yVYkp6yFJBBrXaLXeHu5pPP7POOgXY48+D+OY0jp4FR3qTGxhSjPCS0wNR8vsFhGnP+pqC4+wPpX8JfrCt/5NCZ+l98pYbFL9snhYt4dLJ0SZCmwgzq8A2leA+lh95E8AUhQRP/gNVZ1r+2bnyhGRldsJXPdO7FnUVPQl4GwPgtMZORbwbqrg== 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=38Gdhk3KN04AsB2+FtnOPufQa9OPd0VNkEYGnuMTvIE=; b=nwjekkMuS0CHuT3+UAbsKiXQVDklKPQ/afh81desiWCGGAJTnPDNmrjWn4/lzq7dMsmJu1LIf5rfFSxjiYL/zGjg5De6oTRA2PbKddCyQ0l94K8FSdQCtUXxTcL3PoN9Jl+fQ2XwzO6ssYkkPgXlrFruGMQE8lEBykH6lfnF6wsvR780XQHyb13i3Jmtdn2kxXYmp7ydW9xN2H+ZUJdf615s2sogdAxm0DbyJn3p/QAFYvqFuJ21AJeaGG9YYi5Lp+4ZTsmij/glCw+1D2jD/beBrGurfgKzNqHemBtjvaBbZfYxN2yV/JSXAsNMQpXrLP92XjjlCQ0o5YvYY1sZsQ== Received: from DM6PR17CA0012.namprd17.prod.outlook.com (2603:10b6:5:1b3::25) by CH3PR12MB8536.namprd12.prod.outlook.com (2603:10b6:610:15e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.37; Wed, 17 Apr 2024 08:55:10 +0000 Received: from DS1PEPF00017094.namprd03.prod.outlook.com (2603:10b6:5:1b3:cafe::de) by DM6PR17CA0012.outlook.office365.com (2603:10b6:5:1b3::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.33 via Frontend Transport; Wed, 17 Apr 2024 08:55:10 +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 DS1PEPF00017094.mail.protection.outlook.com (10.167.17.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Wed, 17 Apr 2024 08:55:09 +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; Wed, 17 Apr 2024 01:55:01 -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; Wed, 17 Apr 2024 01:54:55 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v3 09/10] ethtool: Add ability to flash transceiver modules' firmware Date: Wed, 17 Apr 2024 11:53:46 +0300 Message-ID: <20240417085347.2836385-10-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240417085347.2836385-1-danieller@nvidia.com> References: <20240417085347.2836385-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: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017094:EE_|CH3PR12MB8536:EE_ X-MS-Office365-Filtering-Correlation-Id: 80645e5a-8c51-4fb3-f04a-08dc5ebc1653 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z33CSchLGsZB+/hYART6kqnVhrHLBKgUx90kfJokbXFLPIj5ddSZEODg/vft5i+2TkFlX9flmA1aVO7XJpH142NmuDnooaEaoyIoeYSw476zOHb7Q5/0/FhUOk1GJjI15XQbjAiIvqiH0aPA2lFd9kxg0S6OeH0+WTODRL5KfSJBFI8KbtQMKcjQSIv26UK/oPv9WpYG3Bb5mFyoVJhDW0aOMPYqlz9+k47sD/+V8ztb2dE8pAY7t/4OdqNHk1gSgY9oKlWa7VUzO5yP3X1f7lKto2+FBSGqpVoc9tYN9v4GkVLnb42XwQUsTJZpNaevuRDm7faT7bFyrlCeC7AD/6G7pg0wsmiBqwr78J3j41AsEmS9t6XstEztmkahmFwiaaxTVz64Q1VN7pzyE1JRXi2nYxqYIKq/MEGN44+IuXdOEmm6ZbKWAFidH0JmEyIzelDQmJ9ZrC0o8vE1ICRhxm03oVow+9NfIhxwn611QxXKCGqObifQFTDdXT9YRZm48qCtmsQLp9SeECD3Yzvvgvm8F2535TOOM90WVmcCrpQWwqOFCuqmn39csBy+TsO15N1WFRQBfwmC6FkMRlBSIq83baAODLHu/fn6AEylKxQyDwC58ODAp359Gw1Fmxcaiq+5yjp+6G1FmGGe0QPTXulWBiWeF8ec3/ejL/+fYQca2i1Nbfwpva5QVQ9HutDOHjbb1EeF9McJ69yiHIolQ0wd1sK1DTcQFmk9FVQT/ZwOV5OKBJ6vWNifFFjCIrrk 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)(36860700004)(82310400014)(376005)(7416005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 08:55:09.9667 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 80645e5a-8c51-4fb3-f04a-08dc5ebc1653 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: DS1PEPF00017094.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8536 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 Wed Apr 17 08:53:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13633035 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2046.outbound.protection.outlook.com [40.107.237.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 98B9413C9BC; Wed, 17 Apr 2024 08:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344122; cv=fail; b=DMi4uLYFhWIP11ZdwcxIDUiIVhCvUCVv4liuJQd2OkaBOof2uMQIYCPvHn/I88W8Ce46ayemAFrwYb2r2ob2pXYo5QJaydkWszm63Qe2bNwmWkODuHJALt5huqSu2E3N8KOvIitA7XnpgTw+p18gOCt3GRkT3Rv+svX1PpKBRek= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713344122; c=relaxed/simple; bh=yZfvoGxUnvDaatNkkEDXy9xr1YOYnlqdKwLC2dw6GmE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VR0//AIO/25zFPrXtINeVJDbmoRav/ioaVmAaSyaAgeWklgQ+Wt+ybVXWv8XTltBxjsrjZx5pChCcDCHsbkmEwRVgA8o+wVwQClAB65q5N/gvfOZ8hZuz77giqtxQ6+HKJSy1pG3Hr9bocX4vwe8X87B4ubqI5v5xF3TBYBlJsE= 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=KyW/2LWq; arc=fail smtp.client-ip=40.107.237.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="KyW/2LWq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J4FRrRWqOXK0HPPf8B2fLROufu+fL/zNvoqFl7Xd2+r1OHGimyqV4xfueA4OTzfnScjv92QeFOzoqzngXEnANNeFUvrXIbIscTP/DNU5/4ATBl9NOUGT9pZsp67o0+LxDmDmTvhX2ZhfBehdMxImneWpdtFsvQyMY9ZDaYFPt+f+Ru9tEpbTSNLXLMsjsoSLMOdqTDtKdCA5BKLwEcBkATZOY2LZIyqyKXluZo3TxBC300kpd2+WvA4Al6hC/hxNw4MBGE2zRIpuP2vUdsAc9ULP+9U0R+a0RNh+PAxIw5f7uZxcFdI59axiEw097ooVUfZ1YJTLXtJxghuBeT+X4g== 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=cvswbEds6bAYk6rJrjgq7aKNV4PlU/Xx1Q6AaZnacPkw+n/3aZf/OrIWJzaJw20/fyAExcvNxTciASpkFv68TgsPNTzWAMND6LmCCvAGEq9uKSNXXtPIVFhrtJ5R9XEOIVgJZLouHBFEISGrsxF+LT2T1XZ5Uuu4IxUS7L6hYTgA0/nbUU0l/KdH5UmTwCVhHSx1pudg5qtGchHTOTAe//MtA+LlwuyxpoCHu4i1GnhtQubH02Tcugy3H5fn26Llrr2Vcu05xsx5TP7dms6eHBi1Fpz3Dij1mBTPsEeQVjV95QZNneHYp8FsrH+aKpvzkKpOvKyHD7jmUKalmLthhQ== 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=KyW/2LWqC2l8Cmw5CP23nU9QyrniKB8AW1mb9oZNJIT2xXsFRB1lhtyg/NF7Di4L12Yir+64gDw9EWQNtC1ETQ9ORCIV6jjOB5Xh8HWwag+A4DndDJ6Xmzw5bsat+nBX3k8gdQvFAhfzZC9jkutrMMnCaS53wtpvE/VsXInk7BhgJ0GXP46vGuAskv7mpYhVwPU818RE64ISVZD0da7R1qdQDAmzklsmvC0MSWwnNiqYb2haKPpVdHjaX4y3ds5JOjH7L5cn6HT2qXYo2ZZZJFCMD8Axv5HyFkdNHCDk2nGrL8I1a8cF80s8TPuLngJv8quXHguTude6uS0RwRitNA== Received: from DM6PR07CA0092.namprd07.prod.outlook.com (2603:10b6:5:337::25) by CY8PR12MB8314.namprd12.prod.outlook.com (2603:10b6:930:7b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Wed, 17 Apr 2024 08:55:17 +0000 Received: from DS1PEPF00017091.namprd03.prod.outlook.com (2603:10b6:5:337:cafe::b3) by DM6PR07CA0092.outlook.office365.com (2603:10b6:5:337::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.20 via Frontend Transport; Wed, 17 Apr 2024 08:55:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DS1PEPF00017091.mail.protection.outlook.com (10.167.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Wed, 17 Apr 2024 08:55:17 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Wed, 17 Apr 2024 01:55:07 -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; Wed, 17 Apr 2024 01:55:01 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v3 10/10] ethtool: Veto some operations during firmware flashing process Date: Wed, 17 Apr 2024 11:53:47 +0300 Message-ID: <20240417085347.2836385-11-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240417085347.2836385-1-danieller@nvidia.com> References: <20240417085347.2836385-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: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017091:EE_|CY8PR12MB8314:EE_ X-MS-Office365-Filtering-Correlation-Id: 72a8897d-6e71-45c3-4e7b-08dc5ebc1ad9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: y6/GyvM0i0oPyJWrk2PpQoTIwDvnU8VT9AUihO3CSeKU13grsVyFDxoCdsIiQncxO6s1t6sdSVWS0bGtGrooDDQwhCc64jhOb0pHXOBt3moWdk73pnsJVsda61iLBdXe34jWEO6MUzf2dS5Bd2d1BqgRkWdOeU3c/fgqTNMJfm23VWL9k2qfjhIp/DfbhrpRvoZHRL1vbPi9O/TvqRTKx+orYnzgRvEjDW3tJ5m1jXX96/mxyaWpzeDtnQtvyv5BaC5eSzvME6jq5DoeBllHlfYK3kx+dJbY2LUqj3fTWkp4GADNGMqxYgUT9SdJXIAqbc7upTNQezHMv1j9T7A40k0qa29G1E0S7tywHGrzm1mT+9FWZS1Qb1NdZZgm3KIxjW6bMgWv/jb6DgeXddBbtcBQGV9wO+7nWRa7+jBvW80Mcf0eCXJpH8I+p/KKiJDon62A8wxqDdIGs9MPSX+cqU3lHPnj3DqGKmQGZyQQn2hyeQt8xOEvuptJyo7vsSs2prjBGy/Wt9QQdb2oxhCsd2eBJGN6tBWbbPSQ7rYNx/fKKrtq7PYUXPdM+ZHsKztKwfBUpolWjHLHr5SUTjK5joUmpxnIxfUTQh5KhUq62E6jvYktIAHti9OhmAameZVJ2PjflQrfpIKTMBQiaVaAEbWiYmhcVlPfOV7BWUROHjf6exDwpCzALM1EkNl+3QKTOuG49/HIDKufd7X4dzkh5WB3SO2sU1z/DObJ0o04mXDSigV5LUob1kIFIDlTGC5X 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)(36860700004)(376005)(1800799015)(7416005)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 08:55:17.5516 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 72a8897d-6e71-45c3-4e7b-08dc5ebc1ad9 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: DS1PEPF00017091.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8314 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; }