From patchwork Thu Jun 27 14:08:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13714452 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2054.outbound.protection.outlook.com [40.107.236.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BD56198A35; Thu, 27 Jun 2024 14:10:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497414; cv=fail; b=JbuWoK/iwaiUodshYbv+sqA1E9EqfWBejdTw3VDwvC4Ul4XRl7i3RVEL27dhPkkDe1QMC5OpDSlceRNYw5X2fQsttoFZ516F/LAho1JDY5Oe5uOrlDl4gnivmbz8QT/XX19Z/FpGa7q6QRwFjvXbmI5NG9pJYb4atRLVwRhBXr0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719497414; c=relaxed/simple; bh=NpEE0ls9XQHFSXMiHmYkeNcLv0lEEe/RUnAq61/u23E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=upusdUgZHtFzrx+59rIevO4sISABGftk6qgWW4EY0+r0TKdRFn9BK4n5781Vg0jnICZNRoVYq3eKOpY8d4VoZnWlFvI6dajY3hMp6veKa0cZ6erMArN1Y7W442ZX36JKTFcjgm+Gw6xYmbsD9913EuDgM7PGgJv23JH5LIFx6ko= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Of65Kjac; arc=fail smtp.client-ip=40.107.236.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Of65Kjac" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HG236lXFjYhrlH7R6+V5Zgg7P7xLZI3Oi7tFFY9tf2dl50B4lHKyqR0EdV18qGLZCCXvxBBtajCJ9bE14TO9pHolzaArWpIdpAsIWw+G3F935i11HmADySeOorpsWCnIDSYx61hAAy+mv51GxkBV9KSlvfeEXcqtQJ1hxlZHv4xLPMmy1nnp07wf6CXj5tfIqfyNRM9u4tpY9bBapBasI3okj0zb0WZaD0iMFMfopxh619RvvUCOSNvKQByHBWpXnupQ85NRL8ID3cUTzBHBEfK0Z0e/kr6Zj4dDkZkeulPK9AnFjDIgny4CTyERUEFZktZK7EkF4pAU7JWk6MHa8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lVyEvTMWPzgG42wVdEcliSwmDHzFLUOue5wVVlomkSk=; b=LecVJV/tMiTXSLrzdZK85GuHkDdc11tDjXk36DwRZ/jeUZbdpVdfplMGdQM2y5oo5AFxaYIV2KD0Sp0SEyNRE9hx6KeuROKVigNb8zMLPKWomepOah0P4E8bRgEMQxDafpPLuLMvxVtr3uvBU02D9SRvwb++nIKC+/nG/FJlDPpH0INYB1WoCYl5qSfTfn244KtSE58jJevdpke3FVD6YJD7k4ojyNBTEUEwfRSDC+K+PMcRPF/o6kdsW0zpM/XtEWkeP0ALTEAaZSlnMYrmj9NlaLXTIke3f8/ksOywpHz7YuGJu+71jEbU107Vt0vSLu2JD8uEoOAzlKPv8JTdrw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lVyEvTMWPzgG42wVdEcliSwmDHzFLUOue5wVVlomkSk=; b=Of65Kjac2b0ZpzY3Ns6tcqicFKXVksKBXR9YvNmc/AOlXmV5JonVYUdC9POoWTsQhVpR6KPUjO3gJge+hF+v6JP7mYr2dPhH9HF+lTCUZ+qIjaPrHnD2d2gDAUPr8mRnElQ2tKXlEAvvhcTsqLmHhBmT3MUiNxqooJGlysIeo96MqURb0uLROoHZKhpdR6W7amBoeOBh1ujLNLhSXNi7JDFP5/ei6n8oCkaVCi7osHxx2Lj2hp2A0b0h2sKQ0TGGhEV7wDNKGSclu/tnj+Ati1dTFM/dX1MoG/5+8CHf/kG6UiToMFtq782QwXE0+9n1Q8rp7Ia020BixVTWjEhFFg== Received: from BN7PR06CA0057.namprd06.prod.outlook.com (2603:10b6:408:34::34) by SA0PR12MB4366.namprd12.prod.outlook.com (2603:10b6:806:72::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.35; Thu, 27 Jun 2024 14:10:08 +0000 Received: from BN3PEPF0000B06F.namprd21.prod.outlook.com (2603:10b6:408:34:cafe::8c) by BN7PR06CA0057.outlook.office365.com (2603:10b6:408:34::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.25 via Frontend Transport; Thu, 27 Jun 2024 14:10:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B06F.mail.protection.outlook.com (10.167.243.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.0 via Frontend Transport; Thu, 27 Jun 2024 14:10:07 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 27 Jun 2024 07:09:44 -0700 Received: from dev-r-vrt-156.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 27 Jun 2024 07:09:38 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v8 4/9] ethtool: Add flashing transceiver modules' firmware notifications ability Date: Thu, 27 Jun 2024 17:08:51 +0300 Message-ID: <20240627140857.1398100-5-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240627140857.1398100-1-danieller@nvidia.com> References: <20240627140857.1398100-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06F:EE_|SA0PR12MB4366:EE_ X-MS-Office365-Filtering-Correlation-Id: 38bbe570-9c59-44c1-9b5b-08dc96b2d99f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|7416014|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?fV5vz6qqCjO+CW662gJtJTo+tTxdPji?= =?utf-8?q?/BYS/oNbQ6vfel89yoXIiGX4mVv4qOnfaTbfKxVvZz2Ox2gX7DCxM60UlOVO+icw0?= =?utf-8?q?oIKUxx0O4s3eE/pjAakxM8W5+lTzGYmd1s+Uz6LNomewpZb3yQM4wlj4Gg0qXASxX?= =?utf-8?q?WDYFz2mfrEQ7JD3/qwyG9+4NxQ74K1daIbaL/+JNem2Jscm4scc+96evo3dk+ZKQ0?= =?utf-8?q?tubSv9yK3OftS9/Q+ME7WcazvXZp9tKfUzW2e9VKZrSJ+l9QsBKfETPZD5M4I+M3K?= =?utf-8?q?Rtwo7HEeDK260QoPM0i5laf7ezfmtB1Rq1Mjeo9gCkGx83JOO6L3k3qCIyHm6Ps1R?= =?utf-8?q?w/EWBhQRKhf5P+PWLDV/scoIL3dWFAYIZZF/T/ydWcgZxj/VBk26k6gcRzOk2k84f?= =?utf-8?q?cZEgCZJehTqsTjgcLj4/Bci2DSvUvq9qIi+hkL1nrIgPjaZ1CNoaCT/2sJwMr/D4M?= =?utf-8?q?vPnc766fIuFFLuvmSPm7MprmC08wnFLT+C67qbyGcaHsJEOtUJQygQz76sPoISDyx?= =?utf-8?q?0UJgc180iT31+NcVrNzPGe8tTuJSldPicwX3eCt3p+2kRwv2A8aupa7ce3uoHV9id?= =?utf-8?q?g7wo73jzq1TjkB5Pimy9CyK5/FadDFWQVWh+7fW9MVfw5RoDjfFa8SHHqJhGB3h0Z?= =?utf-8?q?0saI9wCayVYWf7YD0VQ2wEzSKwfH0/59tZPrUF0ECsVwPmEKcGlKhXOfcGTxhqXko?= =?utf-8?q?Tm2Zr7JXcfpRwUWL9d1l6doyfJwfmK95Rpb6C94LV+Vr/zAvsJDxVY7wNvDSvilTQ?= =?utf-8?q?+QZthOmX76VbyGsZCb+Ys8PiRK//mDENVNlfoO9Vgwawp2LnQPegdGyxS4Oc9USm5?= =?utf-8?q?KOu23iviz3K4RP/Kxs1nMIlcyTKFoqlucnDwQAGoOaAWiqbbZEsatEno6Sfvqoy2F?= =?utf-8?q?z7MJNkhl53krbY+Vj5uPo4qHNBvETfPE7LB42i0I8/rkK8t+509rCDzeG+ZyrPCdo?= =?utf-8?q?lRy98/PsieMQsdebXUkCDKuH5ZT8ZuPQuP0RvsZaV5sIqag6NAgNENmWDmc0vINea?= =?utf-8?q?oyFqn6KxSEHG7xad4+H7lS3BSC1h6lg6LBiAORUthYuHwiVCnfnyHb51lAf5vWis7?= =?utf-8?q?oFrwRuRR90+kzHVR1+aQ1mJmRKOmWfyUIOuz7pqO4o3XdElj4OaB4geQHT/qdNd03?= =?utf-8?q?pKHteBUa+pUhkUfVmVOjpdZH8TryRj+fm36gkVQckVeV6fqH8ZVH0apMmb6Ey+BG4?= =?utf-8?q?5tR7Z8kQP7XzIuAq6tUszYk+8hvKDUGkFWdx7kvTpfYoPVU7A+OiIk6EVjv8w8Kv4?= =?utf-8?q?CoBbIC7Bi5Ung94Ez2K7VFiLfIPQkEENxUzaL5TXuEfNKh2+XenkgUHhJzqhwp7W7?= =?utf-8?q?BBUTnSMtPEctVbo/E3Qw+kTpsLXVea7JaEmZZHkO7W8uxIH9wXxBCSF+no8E6BtAK?= =?utf-8?q?+QtSDXpNa5i?= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(82310400026)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2024 14:10:07.7197 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 38bbe570-9c59-44c1-9b5b-08dc96b2d99f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B06F.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4366 X-Patchwork-Delegate: kuba@kernel.org Add progress notifications ability to user space while flashing modules' firmware by implementing the interface between the user space and the kernel. Signed-off-by: Danielle Ratson Reviewed-by: Petr Machata Reviewed-by: Andrew Lunn --- Notes: v7: * Return -ENOMEM instead of PTR_ERR(attr) on ethnl_module_fw_flash_ntf_put_err()ץ v6: * Reserve '1' more place on SKB for NUL terminator in the error message string. * Add more prints on error flow, re-write the printing function and add ethnl_module_fw_flash_ntf_put_err(). * Change the communication method so notification will be sent in unicast instead of multicast. * Add new 'struct ethnl_module_fw_flash_ntf_params' that holds the relevant info for unicast communication and use it to send notification to the specific socket. * s/nla_put_u64_64bit/nla_put_uint/ v2: * Increase err_msg length. v6: * Reserve '1' more place on SKB for NUL terminator in the error message string. * Add more prints on error flow, re-write the printing function and add ethnl_module_fw_flash_ntf_put_err(). * Change the communication method so notification will be sent in unicast instead of multicast. * Add new 'struct ethnl_module_fw_flash_ntf_params' that holds the relevant info for unicast communication and use it to send notification to the specific socket. * s/nla_put_u64_64bit/nla_put_uint/ v2: * Increase err_msg length. net/ethtool/module.c | 117 ++++++++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 31 +++++++++++ net/ethtool/netlink.c | 5 ++ net/ethtool/netlink.h | 1 + 4 files changed, 154 insertions(+) create mode 100644 net/ethtool/module_fw.h diff --git a/net/ethtool/module.c b/net/ethtool/module.c index ceb575efc290..ba728b4a38a1 100644 --- a/net/ethtool/module.c +++ b/net/ethtool/module.c @@ -5,6 +5,7 @@ #include "netlink.h" #include "common.h" #include "bitset.h" +#include "module_fw.h" struct module_req_info { struct ethnl_req_info base; @@ -158,3 +159,119 @@ const struct ethnl_request_ops ethnl_module_request_ops = { .set = ethnl_set_module, .set_ntf_cmd = ETHTOOL_MSG_MODULE_NTF, }; + +/* MODULE_FW_FLASH_NTF */ + +static int +ethnl_module_fw_flash_ntf_put_err(struct sk_buff *skb, char *err_msg, + char *sub_err_msg) +{ + int err_msg_len, sub_err_msg_len, total_len; + struct nlattr *attr; + + if (!err_msg) + return 0; + + err_msg_len = strlen(err_msg); + total_len = err_msg_len + 2; /* For period and NUL. */ + + if (sub_err_msg) { + sub_err_msg_len = strlen(sub_err_msg); + total_len += sub_err_msg_len + 2; /* For ", ". */ + } + + attr = nla_reserve(skb, ETHTOOL_A_MODULE_FW_FLASH_STATUS_MSG, + total_len); + if (!attr) + return -ENOMEM; + + if (sub_err_msg) + sprintf(nla_data(attr), "%s, %s.", err_msg, sub_err_msg); + else + sprintf(nla_data(attr), "%s.", err_msg); + + return 0; +} + +static void +ethnl_module_fw_flash_ntf(struct net_device *dev, + enum ethtool_module_fw_flash_status status, + struct ethnl_module_fw_flash_ntf_params *ntf_params, + char *err_msg, char *sub_err_msg, + u64 done, u64 total) +{ + struct sk_buff *skb; + void *hdr; + int ret; + + if (ntf_params->closed_sock) + return; + + skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); + if (!skb) + return; + + hdr = ethnl_unicast_put(skb, ntf_params->portid, ntf_params->seq, + ETHTOOL_MSG_MODULE_FW_FLASH_NTF); + if (!hdr) + goto err_skb; + + ret = ethnl_fill_reply_header(skb, dev, + ETHTOOL_A_MODULE_FW_FLASH_HEADER); + if (ret < 0) + goto err_skb; + + if (nla_put_u32(skb, ETHTOOL_A_MODULE_FW_FLASH_STATUS, status)) + goto err_skb; + + ret = ethnl_module_fw_flash_ntf_put_err(skb, err_msg, sub_err_msg); + if (ret < 0) + goto err_skb; + + if (nla_put_uint(skb, ETHTOOL_A_MODULE_FW_FLASH_DONE, done)) + goto err_skb; + + if (nla_put_uint(skb, ETHTOOL_A_MODULE_FW_FLASH_TOTAL, total)) + goto err_skb; + + genlmsg_end(skb, hdr); + genlmsg_unicast(dev_net(dev), skb, ntf_params->portid); + return; + +err_skb: + nlmsg_free(skb); +} + +void ethnl_module_fw_flash_ntf_err(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params, + char *err_msg, char *sub_err_msg) +{ + ethnl_module_fw_flash_ntf(dev, ETHTOOL_MODULE_FW_FLASH_STATUS_ERROR, + params, err_msg, sub_err_msg, 0, 0); +} + +void +ethnl_module_fw_flash_ntf_start(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params) +{ + ethnl_module_fw_flash_ntf(dev, ETHTOOL_MODULE_FW_FLASH_STATUS_STARTED, + params, NULL, NULL, 0, 0); +} + +void +ethnl_module_fw_flash_ntf_complete(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params) +{ + ethnl_module_fw_flash_ntf(dev, ETHTOOL_MODULE_FW_FLASH_STATUS_COMPLETED, + params, NULL, NULL, 0, 0); +} + +void +ethnl_module_fw_flash_ntf_in_progress(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params, + u64 done, u64 total) +{ + ethnl_module_fw_flash_ntf(dev, + ETHTOOL_MODULE_FW_FLASH_STATUS_IN_PROGRESS, + params, NULL, NULL, done, total); +} diff --git a/net/ethtool/module_fw.h b/net/ethtool/module_fw.h new file mode 100644 index 000000000000..ee4a291ac1d4 --- /dev/null +++ b/net/ethtool/module_fw.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include + +/** + * struct ethnl_module_fw_flash_ntf_params - module firmware flashing + * notifications parameters + * @portid: Netlink portid of sender. + * @seq: Sequence number of sender. + * @closed_sock: Indicates whether the socket was closed from user space. + */ +struct ethnl_module_fw_flash_ntf_params { + u32 portid; + u32 seq; + bool closed_sock; +}; + +void +ethnl_module_fw_flash_ntf_err(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params, + char *err_msg, char *sub_err_msg); +void +ethnl_module_fw_flash_ntf_start(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params); +void +ethnl_module_fw_flash_ntf_complete(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params); +void +ethnl_module_fw_flash_ntf_in_progress(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params, + u64 done, u64 total); diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index bd04f28d5cf4..393ce668fb04 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -239,6 +239,11 @@ void *ethnl_bcastmsg_put(struct sk_buff *skb, u8 cmd) cmd); } +void *ethnl_unicast_put(struct sk_buff *skb, u32 portid, u32 seq, u8 cmd) +{ + return genlmsg_put(skb, portid, seq, ðtool_genl_family, 0, cmd); +} + int ethnl_multicast(struct sk_buff *skb, struct net_device *dev) { return genlmsg_multicast_netns(ðtool_genl_family, dev_net(dev), skb, diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 9a333a8d04c1..5e6c6a7b7adc 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -21,6 +21,7 @@ struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd, void **ehdrp); void *ethnl_dump_put(struct sk_buff *skb, struct netlink_callback *cb, u8 cmd); void *ethnl_bcastmsg_put(struct sk_buff *skb, u8 cmd); +void *ethnl_unicast_put(struct sk_buff *skb, u32 portid, u32 seq, u8 cmd); int ethnl_multicast(struct sk_buff *skb, struct net_device *dev); /**