From patchwork Mon Jun 24 17:51:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13709947 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2065.outbound.protection.outlook.com [40.107.220.65]) (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 837A01A00DE; Mon, 24 Jun 2024 17:53:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719251589; cv=fail; b=ZKTonBpM7Dap1z1O/11xgRYnHtv/Ps1w5HY81+WrU0zLR36tx3Tt0WuIAMfK6GHdRZvf/MkToMGFSEiXYCtpP8myLkaCt8n8aOatmTbFSJV1wQoMEAmZh3872VgBbCJYjn8xb0jA80tl5Xh0yXe8uTCJ7A4YREhQ7jNFqQNnzPU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719251589; c=relaxed/simple; bh=5nSKT1Qm2EUIs2NwZcmQuktqRoJNT+6dfV4ueHXYZhc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=O2XP98bhsKYJpCj3aF0enYFvuGXoSb70pGlckwqRGnxbaq6ep+zN/V07JnGz6LfEAIHPsT4jZN0B9rUTRRzI27kIhN0hLWtUMeWl6AGUFhJ4E1RWDWlyJiB1s4yiLLHH9jPxkPDnOuMHMHypf3EKcoQsPzhPi6JL54lCSrq4Dz4= 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=FHEzGx8i; arc=fail smtp.client-ip=40.107.220.65 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="FHEzGx8i" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iXFWwUXBXjJWGdKx29VbDUMbjVMGC7Vlvh017hizAQbAdb2WhI3kHMiD/dvXTQ1344/BzX1Pcj69Djtl33XJ3FVqgG10z7v64K+LjSZEn0aw6UPlsbyU8r4NczKOSGCjwAAqoXJbEFIM3UuqfXfdex3vVzycqKuhVi5/gA2ibvubf7hH0PblLF8iJ8WoAf+IncFeuga8u4vcUB8tOZycuDQHzGW50Eg0ETtAzY4qsQRZIhUteDM4SCpR4Ix5UKwRCcQ4t/lyBPRW5mVyLUgDKoibpCZtti7fXf1wfoIxbzeh68ezFUU8fHgMffqofYhlFYLxIpnwFCAE62xcn/zwQA== 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=qFjiLfMyhNW3bgd3vvg0ZVOs/BYoBQTYyFObF9zZL4s=; b=mxoy6QtuXHDxSLpqDlcmv4UNbdlHGNbDh9Kga4uFPUicL7xLcQL9qI0tocCKEQsm3OU3LlSsGhyhBQWEUFRes6MrywIoqaG9VEmHdHXNkglsXJA/LzX8KSlx+OQVHm9ggZpagtIZhxWyFHyXWfpuTNBdP56Vg/QAO4o98uD7EFwfcxebZYsR62tl09Tuq1oEigmUoxVCQ3cV2B9ZnPPfnOzTqqeaaZ5Wplf9l5I6CIfgppaoYhp3MyDn702zKN5Bad2Arvqz2z/Ic/OI5on5PY/00l+DfvkDc4c8OT+NP4M/7ObzAHRZGRxvEURmvOcLeN1dbSIfA59ZFIBqCDqKYg== 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=qFjiLfMyhNW3bgd3vvg0ZVOs/BYoBQTYyFObF9zZL4s=; b=FHEzGx8iYYYImlrMe1eJPA9jCr0IKNRPef5UTNSlw9SZtum5ye6hjtdd08ZYq67Qa2Pyd9VX7BNY2Fwc3g7qOp5zgDXMtJeKW+RDo4eE4zro2mw5SRnh9E6Si3P/95eo+XKqBuXIjn+rVnbVmk4RLrINh7ocztFlIgpd3BtVO30OpVFzF/bZLCo3a366R4ztLLI2Sm2LpbKukcVb+W/oPdurQRHl4/LWcuySgttSV9yamKB7xFRaXXuMDf/DNv0HX0g0UCj+Sj55fsWAQv6V3ZsPDQjXiwroTqTfpk/6gC6Wy4X958LhVClEqrXCPIkySy4XAwhkkT8Oq9vPxMeJ3A== Received: from PH0PR07CA0031.namprd07.prod.outlook.com (2603:10b6:510:e::6) by CY5PR12MB9053.namprd12.prod.outlook.com (2603:10b6:930:37::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.21; Mon, 24 Jun 2024 17:53:00 +0000 Received: from SJ5PEPF000001EC.namprd05.prod.outlook.com (2603:10b6:510:e:cafe::cf) by PH0PR07CA0031.outlook.office365.com (2603:10b6:510:e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.38 via Frontend Transport; Mon, 24 Jun 2024 17:53:00 +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 SJ5PEPF000001EC.mail.protection.outlook.com (10.167.242.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Mon, 24 Jun 2024 17:53:00 +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; Mon, 24 Jun 2024 10:52:45 -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; Mon, 24 Jun 2024 10:52:39 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v7 4/9] ethtool: Add flashing transceiver modules' firmware notifications ability Date: Mon, 24 Jun 2024 20:51:54 +0300 Message-ID: <20240624175201.130522-5-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240624175201.130522-1-danieller@nvidia.com> References: <20240624175201.130522-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: SJ5PEPF000001EC:EE_|CY5PR12MB9053:EE_ X-MS-Office365-Filtering-Correlation-Id: 8df83e5f-94a8-49ef-1c05-08dc94767d17 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|36860700010|7416011|376011|1800799021|82310400023; X-Microsoft-Antispam-Message-Info: =?utf-8?q?rYiy1RDCeXDXYlBn1NYbMZ2CNMlz8yz?= =?utf-8?q?EaplTJrLGjXQgIwoI93Onekv5KABQN2cQ2Wg1IQq6O9/RRWDNe5C1hQW41cu7IQIy?= =?utf-8?q?B807nzNq9yRqtneQB8wlp432DBi+/GDOqKTLT2uSG0qNJpQ/C5CM7AG6StIeGZRg/?= =?utf-8?q?+Rqlwb+tudaV/rYvlyTnHZBINiv6EaLi3gnjOR/r0fcYwFqZ7/n7UGOHfIPw3/t1h?= =?utf-8?q?hBuNH8wSRTDk0R8xK0K154GaO24uqCX6vLhAUxLj7MdjT1pI8+I5RKVyjgx34DRwq?= =?utf-8?q?x4zcbTJCO9T6dTXPdrJPx3YqdeNdYQek9Vqv4Xp/fE4OwPilDJRKtc04/H4zCYmAc?= =?utf-8?q?2N2Vq18XBrkWUXyqWcUx2QiDGRzw1rVmxTuLuOFb9PPBsK3EdqYnIp/2YjS61zwoJ?= =?utf-8?q?VN0R6Luaq+Wka3TyW5HKeExrYSXd14mGmaZAi1kTcAyhQ+ZoQDKHSH5faEE13Q8Ln?= =?utf-8?q?IQ+UwJ4CQzHGezcQfhusYZyx6SVX4U6Y8LD8f2lTydKxEDjzadulCdvTtbFsdjgSm?= =?utf-8?q?cDWB5+ri6Tp/3ng841UD1Pr47JsNJpreBdoiVLEbo4TCdynyhcjIGe5P0CUzPAkYR?= =?utf-8?q?pi+39PNBEIgSyhWHufS8oqRIoCifwAnS3zzjInn0fyElQkIvzleMFb7BzkHL+Esut?= =?utf-8?q?palTvZAgWuFr4lwGIbImAqINEhA+Lr7g1PFdArgTKwMReVRMNDDyhbn5XtgrqjTw1?= =?utf-8?q?cEu1MeIi+l8rVEWmKLBAzLJgyEaJkgSjZSVkCrUJLLbogP15yc5yZCrXG8VuEEgNd?= =?utf-8?q?820mwCKwijVQrKkOQqZHknq6dBcApa8BnhzRumzLbIX5LzkHTCaG68qYpJpU5javB?= =?utf-8?q?PQqrzFqMVbrNOayonqXboQFRLl8NE4GjtobwPELs1S5RVAYDt/4U7BoFj2fVnAIqf?= =?utf-8?q?6hxawIKXb2wEwsIaIiNtH2YPSvEX3IwhuaXRG9VK4tlzjKJe1QMB2h4nrx7WWfUd0?= =?utf-8?q?08L24cZA5JBxItZ9DKBMjSFoD59bQVJ/u7uRue4hNf9gya2wYxp8tywHOuaE5TqjK?= =?utf-8?q?8eB+Hcz+zh6h33/CfcGdkSgKEGMhUxkLtoXBKkiIR9ChhUW83pLcbwMJd/wFblicb?= =?utf-8?q?irOiOwgxvC+rxwcd0YHz1mHGzQ6/QXLUO3Dy6tUKkePtuFPlolcxIsEhtzGzp69sK?= =?utf-8?q?fevW662v9fuD023FAvmgvcETfA6AtH3L4icsOTtuwkRWLtyANVAqgYqODGMGN/VJV?= =?utf-8?q?VfdXuVQlaWTTqmIWhMkha5qE0k9t0YwhpI0CV+vh9nq53MXg8xkVE/YrSC7XQKNua?= =?utf-8?q?tTVGIp6gpEIKcuWbPNeCPEGL/13JsOYgVOYj97Cm6IFUvl8sDScjKzMTCiMG94QT8?= =?utf-8?q?752jdgNLPWMeC2iOu9YOso4Hx5gpu+136A=3D=3D?= 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:(13230037)(36860700010)(7416011)(376011)(1800799021)(82310400023);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 17:53:00.4236 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8df83e5f-94a8-49ef-1c05-08dc94767d17 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: SJ5PEPF000001EC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB9053 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); /**