From patchwork Thu Apr 18 10:34:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13634498 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2075.outbound.protection.outlook.com [40.107.243.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41FAE15FA9E; Thu, 18 Apr 2024 10:36:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713436579; cv=fail; b=F6phGrsg/yj/kROreBHqVyXt4tddcmGdzvJYF+AMxH5Yrh4MicCpw5yOIg31s7PIXpEuogwuf7Bj8/ou0BsHw9GQYdScxLSCTyVN/9QKG0Iaaobn8JBoRUDiM60/wWQ1vvMhCCkZmDbbX3D2W7Uz4BxkhYTjbE1YNcYbL4GgjBM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713436579; c=relaxed/simple; bh=AfMSgWSQr14Kq7RRN+mCLxiDZzv7bYqh+EGqO3emaZE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=he4ot6ypJ0MdCvpdhy45IMUkY8UdbE1CxbvSRwR9hPmQpFh4ynhYOBRH11+wNpobCHBsxh5pWEgcIKyMVqO20pUZWssc3ivxT3QqZYAPWUr7M9sk9Y4uxo5uL/pL+EQruEst/y2BK+AHQrc2Ds6K2NPLIiHxC5/yvt0c5aFjZEg= 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=s9RPnKaZ; arc=fail smtp.client-ip=40.107.243.75 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="s9RPnKaZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TueO2NttTaS4ixHqf1MIAePwtHOoOQEylgjTuE2r3R/tT98wjO4WhYTZrF6cP5zzXaabz9PqzoiIu7dSGwkejScVhGUTkVSvqUegrJCEt0H1h32vP34G8mTtcavo84HUq9Nf2tNGitz3wM/FOyXFjr5gRMfpwpMfmlINcZ7bbrduYY9iHNXUxX32IigI8ptskPwZyijw9HFPm6XavW8OcLuuTS4/mSVBN+mDuo/n6+ADBvy5SEQCsg4Dom75o+BITxAFv3M8J+jB8sgiyaEW6vBdt+cAzeUedvVt0vDtOMrT5FOUkwuTtba+LnmnBelxLVUnQyIISIIX7vZOEhd3mA== 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=l4X+8DZG+0U3cQ4Yq/kHZr8PZIbUFYcUsYkPHnUarPLFUa6o3rynGipzhfNxSe9000+LCBDWBfmO36G4gnQslwrhrqAOVdxPN2C4eNhvDCM2EmwXF50QumYYPQ9Y9JbOghF/eOz4qGjN0Vu6B4OpGba71z4ex9GhO90Ig5JDZcElnUeCGkRobdqVN1yF0ui8JJi71DtNNi+zwuVtjyCCp+FN5xLyKyluG8wwJ9PNkppfgR+bCAgo4G2rkNCrtNsXU2HAE1hk6jmhh9xasTpXnqbpW6Bb0fg95lo5ABTC1ijdpeSjKs+IMZAIB32H4kqHe81PCxdw3WwK1h0yEKKeMQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=38Gdhk3KN04AsB2+FtnOPufQa9OPd0VNkEYGnuMTvIE=; b=s9RPnKaZ01kMr+Hpk5SPOD4Z+JQkS3bUtvkwYyrc/AohZnA6pCM/kM9AfbsqwOxpcCj0z6+BArgg1CO3kCiq7G02EIiBGrnWAct1J/xG8SMEEdJIa6g1meg00OkuKALM3ZMcWnmvsnep/4XodeuifjxnMlRZg5NISkR1yvWpYmFSz7tlaxGmglHbhdcVHUXbPMaRMZTx1298xHHwdPduygmwpoYPmL89ge31PczTgP/rfZ5qJRVZLDZogAVRob+YVz9c69NaQb+sHZeA2kE2VtdvS/vnkPYgXe5ujj2S0kF754fuNe3r2W8RnXSnV+q076x79qFwg56o76B2OczJ5Q== Received: from CH0PR03CA0081.namprd03.prod.outlook.com (2603:10b6:610:cc::26) by IA0PR12MB7554.namprd12.prod.outlook.com (2603:10b6:208:43e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.41; Thu, 18 Apr 2024 10:36:15 +0000 Received: from CH2PEPF00000145.namprd02.prod.outlook.com (2603:10b6:610:cc:cafe::e4) by CH0PR03CA0081.outlook.office365.com (2603:10b6:610:cc::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.43 via Frontend Transport; Thu, 18 Apr 2024 10:36:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CH2PEPF00000145.mail.protection.outlook.com (10.167.244.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Thu, 18 Apr 2024 10:36:15 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 18 Apr 2024 03:36:03 -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.1544.4; Thu, 18 Apr 2024 03:35:58 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v4 09/10] ethtool: Add ability to flash transceiver modules' firmware Date: Thu, 18 Apr 2024 13:34:54 +0300 Message-ID: <20240418103455.3297870-10-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418103455.3297870-1-danieller@nvidia.com> References: <20240418103455.3297870-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000145:EE_|IA0PR12MB7554:EE_ X-MS-Office365-Filtering-Correlation-Id: 21584707-d2dd-40d2-65cc-08dc5f935fe7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DWQyXodm87bDsP0+Ul56ZJG9e4IAT/bS39X+gcI6SVB7HUdiA5tEug2jco0fGjPy1Wp5qeNl4Xqx7x0sqjctRgD459TPpdKNCQSMa59P8/JSAfaQP0aaRDS/pE+ZJsjXpJq9Fiv3c/dw/eXHYYcI+grI/zlv9eD2VwcnJrHKZYu4zZpcFkgKUA3oTToaiyiFsQECsaKqdOF+gmi233WQU5OxzgDJUNjDUJ+UH2b11xPoEwxgvnV6b3GJLtqyO7B7F2nKU5JNFzXjtZjwGIgMN3+RlroGpO9fqBIPI37uxmoGdPt3SUgKcxGndJ8FvdNU+/+u724IuHfgFyTICVjSIjaSoQfd1MIysrYNw6YUgbpYAHxLBu2IZQovoA/BxUOjqtHw8BZxVB8wemNxnS9zbSbn4PCc/fyNDJRb/U4isZgU8I/cgfuOHk9VCFF8FFYfOIupBYeIOqjVIYHqe7NCEFSQeuDZMLXUaayNlg/IyQqFfvqmaL77dBfIULiwHSSGegnCUKDfsOjfr8G1Q5UzP8RmdCu6PxKyEP3uE3sLp8jw/lCzPIj2b2imSqTZtRMxZfbLLhiw00gcWomnvUAgNie1ZC4SyVorStMYkNCnNwdPvuOp3a2CvyTTVXofOwKQI6ohHsKLrY9aI0JxkDmsGgPcFwQj8Kd5snKSOj0vjAkYqLA2XUKORPZE+qRLPGsItAs1VXClqf6Tzk0Y4BoFvCGsxsPQHPGjWl6g5QapSyFiFEeqiRQd70GvEOKpqZdL 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)(82310400014)(1800799015)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2024 10:36:15.2036 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 21584707-d2dd-40d2-65cc-08dc5f935fe7 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: CH2PEPF00000145.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7554 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];