From patchwork Thu Feb 1 15:25:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13541254 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2062.outbound.protection.outlook.com [40.107.93.62]) (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 1BFD016087B; Thu, 1 Feb 2024 15:26:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801194; cv=fail; b=dlDVs+GJJp50PZCN8Gc7AE6q920R1RwDBenAPp/O0GnmDAa/OvXTyPVzJscFkgs+ZGNFfAiSVsFmBoTyTEjhikq2uN/80j/PR5WzB21VxOqR1JWWul7IuPI+CW+hd++Q7WONfuiF1scjVdAC2KrNS74FwwPr5pNIPDD88yZkGQY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801194; c=relaxed/simple; bh=h9ryWNrAPmiwqgxmYjWslpMoTd+lRsgSyiiI4Jt8lKk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hfn167nvhFJ4eO4xHjI4L6PaB8MUN0456nDxrYjA0rjIAiN7oPPzBXdnfj9h4WeHEaUmLEx57SRJ1/6GLKiqGMRShzhl7WdjNFz3ZzTRkk/Fu6Lk6bbUK52z4muORPYI+OFyJGq4MNMYjqPjpGD/RTU5NhXOgNSYf3bO/zPLQZI= 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=ADJJPGqY; arc=fail smtp.client-ip=40.107.93.62 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="ADJJPGqY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fj+J58CWMFs+g4QPL7pS1AJQ0OBsWB/+LUaWmIzFjtxIEgSZkudbjnPC4MAI3NRZBN44l7bcapzUlW4XMtfyBzOxfZIDd3vfgF4dgXNG6QqVXZxMa0mtoQC0lEFvuglepTQexPDDMFZqjru8SYTsAbhV0cTDuSNyPhY83dv105Lv2C4jpmgdlMvpcirFrd3HOB8mCPFNdf9kaUKC1UlRA60uFb0QHq9VElzSTeK+QpO0oY7o1raVNOv7SgI1zUWHXUmgovGhkMdPcEy1xB+UeHwKlPIALoSg/BV0Gd85vfxSL0rBslsK/zi7DbsxiVjPvCTpmvPd9K9C06cMk48NaQ== 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=H3PC/+1uJFlUiyz7S9YxxWuPKeMNKBK8ksotcT/WTTA=; b=bbFNgkT3ujPRoPl07qv6aWoSJlwJEPzSnDWP01mZ3HwKNrTl7dTwoxLY/Me7SMq36QBbeznLo0oKefAOjFFLm7R5tBZbMbjM0ZUA37qceM7LbdIcKkWsGFK4rJC4UhXM5pKgrikd/mL0hLIWSxzSJAfgucpU59oBUuPaP7+c27k4HxMRutJqtG/dlp8pRAXF/gSmHdDtzjgJpKhk4Ms91NaRSSYMdxqUpQxf88TGgShZylWkqLB1pnOTgaTrm48cXZMH5cxw7bmLI1nbegpfpZnO5rWj1bvpMlCyqjtZM0kBsCL+Dyqnow87fz1L01EIkmobz3ccrks7Sbxs3sBjVg== 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=H3PC/+1uJFlUiyz7S9YxxWuPKeMNKBK8ksotcT/WTTA=; b=ADJJPGqYH6IvEeQcPbLAOfy/8pyf83eYpJCKmBxSTVkSLPVoSFpEy7mJad5jI+RcZ1GfZVkwwAJfLGlT9G5VUgN1nlFQGwvJ8YrxFyYxSzqfe619sV4cpEX5s8Q0LHUJEI3WDX5FuKdPym139jIAEyiwqfvOzZnizAidKW4oWQJ8HdeV9S0LNq1pWqdKL16xOAkqMTb5tqJqXY0EfOz2UVezwefLCEDUgF0Ja6PmYvNlIXKHRUP/ZzDcMLrDSytrZvQrvSOX2ozI6KsDDx648r1oBjzxxiMCndVXfjSPnwPE9DKniWbnpOdaH0CRhE/AG6qxlVQ5dOy6gFt3XH0VqQ== Received: from BN1PR10CA0018.namprd10.prod.outlook.com (2603:10b6:408:e0::23) by BY5PR12MB4968.namprd12.prod.outlook.com (2603:10b6:a03:1d2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.34; Thu, 1 Feb 2024 15:26:26 +0000 Received: from BN1PEPF00004684.namprd03.prod.outlook.com (2603:10b6:408:e0:cafe::cc) by BN1PR10CA0018.outlook.office365.com (2603:10b6:408:e0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.26 via Frontend Transport; Thu, 1 Feb 2024 15:26:26 +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 BN1PEPF00004684.mail.protection.outlook.com (10.167.243.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.19 via Frontend Transport; Thu, 1 Feb 2024 15:26:26 +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; Thu, 1 Feb 2024 07:26:12 -0800 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.986.41; Thu, 1 Feb 2024 07:26:07 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next v2 9/9] ethtool: Add ability to flash transceiver modules' firmware Date: Thu, 1 Feb 2024 17:25:01 +0200 Message-ID: <20240201152501.3955887-10-danieller@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240201152501.3955887-1-danieller@nvidia.com> References: <20240201152501.3955887-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: BN1PEPF00004684:EE_|BY5PR12MB4968:EE_ X-MS-Office365-Filtering-Correlation-Id: 17e37ae5-fcbb-4f79-18f3-08dc233a27f9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w45sX/4Ep/nRtHW1gwN5uH1wLEhzDIQ2lG6Z0fee6bvyrC4gJlSRBG624L3z68iqVqNpxlbKGzzRN3BK6+dhAFfyHoS6CwCM4eMrE+aRmKTUXXfIMGxvcF8ACwWmQhqbOixQjNi1jvnjMcQhJb3Z+yC/u/ov5VX5FvYbe1dEQo/p4nN29OZXcVrd4cdhjFgtyrvUswZuQGu6/8v57AEIgrxH6qDHBfr1M3KIDXH0o8kOMVL3DMlhd2mFELvdC32ThK2w+zll/dZq/oKGPGjPi6fQ7BMYg/TINkzxeaR7HHlTgqnlIFzK+T3TokObR4PktjjmKnzTHcVZAhivt3in0Z+zJIEl4lS1bX6GUdyUE1GKsG6AGvwWp8KI/gSVLNEFcBzMQW5+hFIM12JA9HCzW1aPhbf9uNVIg17Wm5KA3YpNtoYbsZvaBI33vfGS9PZjLk4X2JsJPbtvOkYzQ857GpVMId86gT633q2YDPwz+/dTz0sFiZV4yXFFuvWyqoNC19n2d7tF/Xf27jLDfvHyHBP1BWW47AoFXqM9AtnkPQ+95eyd1/xoY57dB4UhTEAkMx06d4msJk79DTKIUkf/TT6JR6LswszQ/dM29sTpSS/8nOXd+k9yxA9OBk+m3wIu2QHqslXLeJDdvuoNDAIR+Dgq8/IZGDAx+/Zqcychx1r53XL10eudEQy/63vAcOE52y+y2FokP4W+0Fs2KI0gtjHTP9upuHu4bjQcpftZnNgdj7ZC7urrbdHG0HR8Ps0R 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)(4636009)(376002)(346002)(136003)(396003)(39860400002)(230922051799003)(451199024)(82310400011)(186009)(1800799012)(64100799003)(40470700004)(36840700001)(46966006)(36756003)(16526019)(8676002)(47076005)(8936002)(2906002)(5660300002)(7416002)(4326008)(6916009)(316002)(86362001)(70586007)(54906003)(70206006)(478600001)(36860700001)(356005)(7636003)(2616005)(83380400001)(26005)(6666004)(107886003)(82740400003)(40460700003)(41300700001)(40480700001)(1076003)(336012)(426003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2024 15:26:26.2979 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 17e37ae5-fcbb-4f79-18f3-08dc233a27f9 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: BN1PEPF00004684.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4968 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 --- Notes: v2: * Alphabetical order on includes. * s/request_firmware/request_firmware_direct. * Add GENL_REQ_ATTR_CHECK() on the file_name instead of NL_SET_ERR_MSG_ATTR(). * Remove file_name from struct ethtool_module_fw_flash_params, and create a local const char *file_name instead. * Rename some includes and use SFP_PHYS_ID for the SFF-8024 identifier value offset. * Remove struct module_sff8024_id_rpl and use a one-byte local field instead. net/ethtool/module.c | 162 ++++++++++++++++++++++++++++++++++++++++++ net/ethtool/netlink.c | 7 ++ net/ethtool/netlink.h | 2 + 3 files changed, 171 insertions(+) diff --git a/net/ethtool/module.c b/net/ethtool/module.c index 09cf11564840..2172cd8c95ad 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,166 @@ 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, const char *file_name, + struct ethtool_module_fw_flash_params *params, + struct netlink_ext_ack *extack) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + struct ethtool_module_fw_flash *module_fw; + int err; + + 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 (dev->module_fw_flash_in_progress) { + NL_SET_ERR_MSG(extack, "Module firmware flashing already in progress"); + return -EBUSY; + } + + 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 fe3553f60bf3..85e27bdb1f73 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -1129,6 +1129,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 9a333a8d04c1..46712c9531ae 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -441,6 +441,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); @@ -448,6 +449,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];