From patchwork Thu Feb 1 15:24:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 195359 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp230902dyb; Thu, 1 Feb 2024 07:26:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHUuctfWZplfxs6XQNtKGst9rMaLmbM0RQsSlUM6NCg/2fSdnSM3vKEaNj0D/VSPuu2Dw9j X-Received: by 2002:a05:622a:4d3:b0:42a:ac1a:eaaa with SMTP id q19-20020a05622a04d300b0042aac1aeaaamr4616200qtx.40.1706801189636; Thu, 01 Feb 2024 07:26:29 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVgAOWvlSQTv3nHyFCMcfNU6T7USEfCGA7NmjU7R9NfxL61RWc9KE/4doCmYh6c22hcvHuoKLrQL9gpCVo8qgmaByYhqQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e13-20020ac84e4d000000b0042bf2dad4d8si1566647qtw.233.2024.02.01.07.26.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:26:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48397-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="Ad5/NOGO"; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-48397-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48397-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 618E11C21973 for ; Thu, 1 Feb 2024 15:26:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7C67626DC; Thu, 1 Feb 2024 15:25:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Ad5/NOGO" Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2089.outbound.protection.outlook.com [40.107.223.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 DEB7E5CDE6; Thu, 1 Feb 2024 15:25:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801149; cv=fail; b=LX1DLt43pis6LXVJ9xWnlxZhQuPL/e5S3sX5+zDhMUNz9ZMUgKQ5Rr1rwpjl82I+1DDGetmTrz3M6F7v8QL4ODHEdDhJEJoyCbXMv/QFDuyyfmLmkbTwDZ0DHE7vqf0k8AwbHvDxfQfevko271JelEbaqE62VOEGK17gyCvdhq8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801149; c=relaxed/simple; bh=YdCe6dGdwhkGwWXk6D9MdDO6QbJjHTDmocAKDe+HJRQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DKM1jNOTEjLtV2C4xRShzCcXTPDL0n240oC8CcN06ECXrQ3+AyDr9onldc54LQ5/h1i+iijne13IrKQxARAfShdQRZ7N/xGuUxvTGXQ7TwnTnTi1TfZcryTVW+gm6SzMeJB94TbuDdp39lfLD+K4deGvvSIAWdo0qB7+fWRezMc= 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=Ad5/NOGO; arc=fail smtp.client-ip=40.107.223.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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DBM1C6UIa1blRT6/ogudMuwSHTDxiPprKrQrRKHiKDeS7g13QFiF9kdv/kSysP5jqBR+b4HIsHPVhwjGerRDEDR0IEJCwCdmpHGvAeN9Fn+X8CVQmrhT6+s5EVXO9dHvXWuoTQkaaVpOjWTBSnwOWHRutx5WHT4i/TDXuSUlwTSr8ga3El+c9uSJeP9UueLvLQ5XRY2vUkUCiDfDeeBzlE16n4SGMd2ObuJKFJeF48MergT6JR9VkRlIJ1O1Ju6EtYMwMwTbkWu+2QKZuxnBaGjqNy3nylKqJwO/mwxZgCzaCPQrwVO6KPlflFN9la9KNquw6FoCdKI8jl0D0uVjJw== 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=b8kM0BmRYpQ9HDskPkYDaA/HFuYdIaQrpfkMGqUwVRc=; b=hhwSyVowDjyULcvtpaerEytPAP/uZEA5HfvTv8Ee1D5RPO/NjxMW6MrMyzp8Yin1aKzzZ//VgVf88odUfbWETscrplKKRcn/jKuEmg8Nrj5zXiwHOHj7dBrnJfwzpqMmlt2Grzw07eEN61KvnwxO8wpsPHZSyRIeL86hmNh5Mct/5L1a77RuI55/8tvE9O7IqI+oQ3kW0c+A3cYK7jpIHv+EN+sP9IdObBpi2ZjDeHW5j1lC9x8zkw9BCAH/qUqhjqhwVC3YKod0G6DA0eJGHPBXdVexf4mFnxTP8AjLULsW1QfjQT0tlQ2B6d4TOw/mPxWcKCAJ3LBhvp1UXX1nmg== 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=b8kM0BmRYpQ9HDskPkYDaA/HFuYdIaQrpfkMGqUwVRc=; b=Ad5/NOGOWjNdq+caQcaIYUL33HwGhKdnA7reRwErmdneAKnaxauwiaE8/3Ku9EkZjUpEj43Z222aPVcjk6SCDV4Q5pex40qskyD1UV/I6NVPnM4WJ3P+L6JJCsAGejx+OS/3/2MzAL/5mxpD45UllwuSGKoIKN7mZ44LdRL22tT73RWy3+XYLF+a7Yt1MLQDf7phP+GHEqaV4rWHNlgnzHPqSwo1N3G4mfl7lYC+xf4dVzCY4C9Jctmgw6FPPnjwmOkl5WfSB3F/1+aKYmw0IbykXaNHK6oN97LCnjpLO/BmkDgbWHAPDWddyNlXzzf+JffD/i4cPcC2x+B/8Ys5hg== Received: from BN0PR02CA0038.namprd02.prod.outlook.com (2603:10b6:408:e5::13) by SN7PR12MB6910.namprd12.prod.outlook.com (2603:10b6:806:262::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Thu, 1 Feb 2024 15:25:44 +0000 Received: from BN1PEPF0000467F.namprd03.prod.outlook.com (2603:10b6:408:e5:cafe::65) by BN0PR02CA0038.outlook.office365.com (2603:10b6:408:e5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.29 via Frontend Transport; Thu, 1 Feb 2024 15:25:44 +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 BN1PEPF0000467F.mail.protection.outlook.com (10.167.243.84) 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:25:44 +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:25:27 -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:25:22 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next v2 1/9] ethtool: Add ethtool operation to write to a transceiver module EEPROM Date: Thu, 1 Feb 2024 17:24:53 +0200 Message-ID: <20240201152501.3955887-2-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: linux-kernel@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: BN1PEPF0000467F:EE_|SN7PR12MB6910:EE_ X-MS-Office365-Filtering-Correlation-Id: 78353046-695e-487e-fe6c-08dc233a0f1d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Y0CHsjYrCHAWG9a/NT5/5gt6JytJl2FFvOTqjQInkwkXR39+5pkxiUXTbojiUFrXAHhrdwhkIKzzdBGOfXOYXwM4nfcaaw2GczGbD05G9z4KtIsmy7r+AqhA5YHwJMmStjiYmLMrv8uTGMCtetbEBFsvgHFPxN51FyRRUr/pizghAHk2PkPLRIrnOICHY2cUAH8NpnMxOAf+wf5Fz+Ucu7ffHoTYc/DXNv1AdfYHDpvV8yHoUGY0OPz3bbEEcNlNd0pqoCfd4cMcmMCAcvE7lefbEd4AEWBLI4lKQFzTlvKpn9fOuAspTa9Kt+8CuSqswQsPX6+8oPhUq5YePj1Bh2N+h0xWItJpfLiTEyVo60p3d0MD6U+OgDe36YIrIO3KtclGQ/y71FhwFfztQ8dHa+aFr6ketlEPYKBVj4Qn8j5zvnDNyfD8AUje3MJYYUsaYlYkrtafV0ecTIf3A2WBP+YwbukJiOgPEFHrBRbVB1f9GmObc0pjjLeW8TRwSb+wA9TNga1v/OKY4o22CeBzsx1NiE9XNwopDaNS50I/r1Baqk71mKO+BQqHrMthymhJAd9VnbWb49ld5D2dk/xQl2+aHpL0gPmmfwmQzv8acgDmdj45Xj5twbUO0tliHqQcCa8qB8LQXsGufMG14ANmWmZ8IvEC/yjf+fuEqN/4BMEhl40DtP2120ZDGCS1cJ7ORs9sndYXWiGPC52vBn47OHC+1OgztabkogEl1NOcL+r0puJdHXh4nOfmrKDNb22H 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)(39860400002)(376002)(396003)(346002)(136003)(230922051799003)(1800799012)(64100799003)(451199024)(186009)(82310400011)(40470700004)(36840700001)(46966006)(336012)(107886003)(426003)(26005)(1076003)(2616005)(16526019)(41300700001)(40460700003)(40480700001)(47076005)(316002)(6916009)(36756003)(83380400001)(54906003)(478600001)(6666004)(356005)(7636003)(82740400003)(36860700001)(8676002)(2906002)(5660300002)(70586007)(7416002)(70206006)(86362001)(8936002)(4326008);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2024 15:25:44.6435 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 78353046-695e-487e-fe6c-08dc233a0f1d 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: BN1PEPF0000467F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6910 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789710764339827725 X-GMAIL-MSGID: 1789710764339827725 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 Reviewed-by: Petr Machata --- Notes: v2: * Rephrase kernel-doc. * Add a note in the commit message. 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 325e0778e937..8ef21f66b129 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -474,17 +474,16 @@ struct ethtool_rmon_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, offset is from the beggining of the EEPROM, + * And when @offset is 128-255 then it is the offset within the + * specified page. Offset is in bytes. + * @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; @@ -789,6 +788,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. @@ -921,6 +922,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 Thu Feb 1 15:24: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: 195369 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp251384dyb; Thu, 1 Feb 2024 07:58:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIpPs2atQa/A5j9xkRPHW1yTdEVU7KZO9UtRlS+RnVxmZ/iGnZ/WO4h36I56dqBlzi+EA3 X-Received: by 2002:a17:902:9a4c:b0:1d8:94e4:7712 with SMTP id x12-20020a1709029a4c00b001d894e47712mr2460303plv.29.1706803097963; Thu, 01 Feb 2024 07:58:17 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUiwX0EaLlDmJ7VWahb4zYOTjh+IwxsMh5kSzwTAxPPIt6n6+i88NGrhCAMCYJcojFgCP8GejXxds+lVud7jzm1JZ9MzQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b14-20020a170902b60e00b001d8ca3a9d24si9332621pls.434.2024.02.01.07.58.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:58:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48398-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Z0di7A4i; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-48398-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48398-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 365C1B2419F for ; Thu, 1 Feb 2024 15:26:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0F01779FE; Thu, 1 Feb 2024 15:26:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Z0di7A4i" Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) (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 793C7779E5; Thu, 1 Feb 2024 15:25:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801158; cv=fail; b=GaD+WQGOctDQaMGWJOT77YqN7jJBUdoUvGm0uvN/ojXhp9EEhbddjTpI62y0MSPhqXfz7YAIlPa4r+3Siuub/bT6S4V/Icv13nuFDZpsvmSo4WXXgJhnBDu/0yk6DFw1aqp/Bmr4Mg/G/kRNjPS4RVvdJOjuQQ47A2Dj7X3OXhk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801158; c=relaxed/simple; bh=KFVywDxvcabGiZLQ2PTyeoIjWiJQ/vPZTqOeGUhPh50=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UL7NzMJqDYp4t9PzPP7KfJVvzlU8yzvSTc53LJOiyg2znAqUVc+fWSU5WPNYlm22TN/i4k1B8/QxIXDEKy5GBdSLsBmlFe9PgqkYOKkeG5KK+SvrSRoDnj52GNGNqE9pqOshGE88+2FOgR51E1YwBHu5cJL0BeBzD5LWPypOuWs= 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=Z0di7A4i; arc=fail smtp.client-ip=40.107.236.41 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lEiYYCHrzeXWZQiWpF8vX7rPrIH+CsIi1n08J5lY+D7LVwcGn92CDD3qq9LXYQ0eacg3Oe7yZ1RGlaWB8xVSRcAjzvHdr4o8B24FY+0HunOOyrfNjmhk+K6zAlPwTtVPcFnNkXIzaVGX/cSosBoyjBL1xx4oeAn+OJerlZ17hV0G/MSOI+uoP8TuuYwx3kko7JV8Mj4pAdgZcZYAMPqViUZ8U6WUm/Kd/bfRT9uufWT/hYAShmThnGxAtvx96fox2Esv/lgOLrV8lar5cCeZYuX3UR67M7nMe74i2b8egr6fRlhHBwzf1LUT00K0u3F3eg9UrbdCGeUeZC/8mbyrMw== 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=tgUMaRp6+NciZly0HdAcBIxz99Hk9j26dTXvVT6J0IA=; b=kbI86wApB4jja2zzcNDthzsp0ZFLk5dFBWBgd0ozHRfe8xIoaLrs3tIBPjUifQ7gl5/u6mF4tOjiLc/qMmW7A9xNJyFly8v1rNp340EumuRBNZUYSHE3jX6rjKhYUhApMiwdMERDFp/d+2AQOMbdaTjuB9lyctT2yGr1IqOFuMy1XBXclT0Su/Xsk58v4mM6h9wryTfhoFuWytJ550vWOmrlmvm0viAEDziG+981pTp/Q4ki08frEH2sOPDpdYSCU+nGqeyUaISWxyTKrapl3u1iOsGE5ExmsLgxM7b7SChkwhz8eVn91rLrf0Eu1L65Jc70dM9aAofTUXwunb5m4Q== 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=tgUMaRp6+NciZly0HdAcBIxz99Hk9j26dTXvVT6J0IA=; b=Z0di7A4iKEOW/asiLfGIUsyW4/kwFxUY/KAOOAIO9scuH1KxhvT+yw08UCpiGMUbCsSyVlBvy5MgKaoERna/MQqU4bS84lAo2HRg0mntUvlf88cVoEl36wZa/5mzB2WivX8Ilns886icg7VyjPDDI9czzXTOWWik2ZFo3xBruTmR4kkEi1bMQMOJQDIzlKVAii4TKhWA0WwfrN7rFMTUqyLF3owi7hvAENB9mn2zeJsBMXag3x9VIhgWSBQCrHQeU8CVtGTw3Afc3lQxqcbTYRokydcSeun/9Ihv6QHY0jlQMb9+fr8xNG/xKa1OYHio4VwUg05ut6avMsxuyOhLSQ== Received: from BN0PR02CA0052.namprd02.prod.outlook.com (2603:10b6:408:e5::27) by CH2PR12MB4972.namprd12.prod.outlook.com (2603:10b6:610:69::17) 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:25:53 +0000 Received: from BN1PEPF0000467F.namprd03.prod.outlook.com (2603:10b6:408:e5:cafe::f7) by BN0PR02CA0052.outlook.office365.com (2603:10b6:408:e5::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.22 via Frontend Transport; Thu, 1 Feb 2024 15:25:52 +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 BN1PEPF0000467F.mail.protection.outlook.com (10.167.243.84) 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:25:52 +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:25:33 -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:25:27 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH net-next v2 2/9] mlxsw: Implement ethtool operation to write to a transceiver module EEPROM Date: Thu, 1 Feb 2024 17:24:54 +0200 Message-ID: <20240201152501.3955887-3-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: linux-kernel@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: BN1PEPF0000467F:EE_|CH2PR12MB4972:EE_ X-MS-Office365-Filtering-Correlation-Id: 987e8192-7d22-4bab-6442-08dc233a13f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rGv9SEsDaKjY/+F1IJfGFgfqb4qfMQE4gpCoZ62CyKlPvIaEVdWq1q99vjzNllL7CEqRR1M2/nMD+XLJnM/WN003znNXkrmSlmY8v+7CCnaV1Kp9/JOz6N+e3lDqbkbwXR5SVVwe8ZVGE70iF4FKuWFJFyLriJQV7n04P4R89sdZ+eERaKAi/C/w+nL9uSPV2jNOxpyVcrd7bEcO1XMAeLBvh3BoB0oA+nmv340mBb9SnbRBzZpdjR2kAwrJEoxB1e5+9SUeK1iXQY27KRqUKeSdLv0Vpi3hxtPvVs94GroGtp0OCQi3u38QFKHV9ldPpt8PHi+uoptAKZl7E1HBXP386HHqnyejbsKSf4qhw6TvdTeWvEQvnqlR85ddWwUB/nv/qimKp/K7DSLV1CuzXXgJFP53/dvIyLSHRMWeNnfxLwToDUmW1Vr2HEEhO3kRrF6RPoMVJaKJRFjoaaHf161TGkIL/EpWTnjVeast5HonhYmmbTlANIwPp48mnUICS438zpLJ9ocjI37ChpER1KwCRqlMyGfTCStVhNbjYpODV4dWavhkhg0gRvIfIzUSjCfldXj2axhSeu/ww6gm6CGQ+3Oh6JujNPPknYVBFewY0QZcYqD93KGJZs/z/Q9oEGZcBMES/gYdk8de1qFDbiBzziGlN9IPaKR50CLOY0OdZbG7Qab4brMtB6OP1kBRqb8SBZlOfXw6zh5MG/xQ6EFdJmGajG+CuYdv3GEc0Xw= 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)(136003)(376002)(346002)(39860400002)(396003)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(82310400011)(36840700001)(40470700004)(46966006)(336012)(16526019)(26005)(2616005)(5660300002)(426003)(107886003)(7416002)(4326008)(1076003)(478600001)(8676002)(8936002)(2906002)(83380400001)(47076005)(70206006)(316002)(6916009)(54906003)(6666004)(70586007)(36860700001)(356005)(7636003)(36756003)(41300700001)(86362001)(40460700003)(40480700001)(82740400003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2024 15:25:52.7686 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 987e8192-7d22-4bab-6442-08dc233a13f3 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: BN1PEPF0000467F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4972 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789712765087463233 X-GMAIL-MSGID: 1789712765087463233 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 53b150b7ae4e..79e4c745ac3b 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 0f29e9c19411..d4fd7f7d660f 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 Thu Feb 1 15:24:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 195360 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp231725dyb; Thu, 1 Feb 2024 07:27:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEyuXcQVTG3M9s3sn+b7pZS+NN9+7sKjcmMcXvE2ambjPoY/4SDl3i3isAnxcH12kfkJ7y X-Received: by 2002:ac2:5f69:0:b0:511:e76:6f1f with SMTP id c9-20020ac25f69000000b005110e766f1fmr1751408lfc.43.1706801265290; Thu, 01 Feb 2024 07:27:45 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUhTL81rDpMP0j5SIkt8E0ypUuS6kDWHh8tv1tYZbLlb7zvRfbR129ZOxQyTKc8hhafI2C5vA9A6qSJWIX3z98tvE/rpg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id t17-20020a1709063e5100b00a3655a4585dsi2179291eji.539.2024.02.01.07.27.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:27:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48399-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="uWlRAYy/"; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-48399-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48399-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 72E041F285C3 for ; Thu, 1 Feb 2024 15:27:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E4EA86217B; Thu, 1 Feb 2024 15:26:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="uWlRAYy/" Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2079.outbound.protection.outlook.com [40.107.94.79]) (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 8FFC5779EB; Thu, 1 Feb 2024 15:26:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801162; cv=fail; b=LWO4v1VFh7T5Gf9uzMDXxPSlNxAaM+do/l9+jLW9RoZnHrgK400AWkuNtkEz6lYcFpR7O4X8A4zLys6+GokM7EnT8Cl+3RzCb4BgEVZhnEKXKIMOXdX1iT0I5/pqfbwD4l0MvFeRFDhe3YTanyTeJSTHYfI35kB+fbnek0wFKcc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801162; c=relaxed/simple; bh=si5gyNKs36hGLG8De4E27+Qtr600ENRJxhY8C4NkxY0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=p/gFA+vnqO8+oewslWwf86YcSlBAp1zur8s8FjrJt8wG+AoyOX21532KerdsbHWPxUzwvUEpg9/T9iOyG/8t3zdmWmXZ2e12iPTiWU5IYiYXqf71KeIENWYk/4r/ZL1p3+7MOhGCLM8YUqhvZCbkABs/Sbvf8OjVcVHvXXClijI= 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=uWlRAYy/; arc=fail smtp.client-ip=40.107.94.79 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h15Z2nTQ4U/ioWvkfdcYTTSWb/Wjwac446Zj3O8IixCG0+/IjgjXkWCb9dhk2SuN26BYjf5qpVZliBdUu5eMWL1MRPP0/DU9VtNceg+aIYtfq2ldeh/BMSZZVzM4/0ksSR9JUjp7isWy9Nio0Ak3ziE1/FCS+Plwg4eziw8YfP1MyY6lbozAnBvIImkPTpUECu3sI+iIPL5bFYBpyf8vfogmFOofIt2aUd7Axl0TLMKZgcfOZueo6f3Fj84GZ7smFPOhR9Lkgc9fWi9G5TmqedF2YI1OyWXE3K9ubMTCU8RukkVd1f0M6OTwIwdlW1favKQnXYkLgkc7f9eN+X3L3A== 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=BUAnH/StJZjgg6j2S4ErHaX/LBWWzs4aXC80hw6QNT0=; b=TJ3VTYw/Oysf3TWEkwVXg22M8cWAqPVuVz36vtdpbISIe//Qo+qxRmSOtNlSmRMvpoi/8IXTEV3mTxPTjEodb0UL2k55RF+xMstRawRypJFdNuD9FVNqtzkGP4hisKwhZ+CcsljF1N6g0a79oH7iuRDWuA+EBT1RgnAoxxFKjiFr7LqteKMXbGDYKBmxe/fCX/cxJQxvnmj3w4qW4cAxyc8stKtkTacujeGkhlItBPU6p+E+YsezWyUKkVO53kZy+QYzvTVygDCcvZfOBx2fiGDndZAnCHonWiSWGLzstQYKM6U8MXitDKYVwg1QirPnScUY3gKDoAKvNbpnqqumXw== 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=BUAnH/StJZjgg6j2S4ErHaX/LBWWzs4aXC80hw6QNT0=; b=uWlRAYy/OsQkdsfM2UGTGzdQEI0t1E1pM6AapOx4yvHM+WFzNLND6CWsnlrs1bINy7IbNQoag0rgybzklJI8cT0wLhgncPZGAoqInkXkTkZBLvO9TZuNqTJREm54AungaG1/L7/wYDGXGyhVe9LuIn5JNQzcWn88Ns9QM0lnoqbXZVqr7/cbmLzlYI02IbNKmheOU11+8pnVHhxlk9P+ROtKkMDwmULn2PQR36bmg+2ZuFnEs7Kms9F9bUFwCV2C6WYb558fUZg1NolX+NQVNRCfv94SO68j2ffTaUqs4ii3adM3GmqGfV1zINp9ZqiQaisPTPCqKCmEI2b8iHSerQ== Received: from BN7PR02CA0006.namprd02.prod.outlook.com (2603:10b6:408:20::19) by BL0PR12MB4948.namprd12.prod.outlook.com (2603:10b6:208:1cc::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.24; Thu, 1 Feb 2024 15:25:57 +0000 Received: from BN1PEPF00004689.namprd05.prod.outlook.com (2603:10b6:408:20:cafe::25) by BN7PR02CA0006.outlook.office365.com (2603:10b6:408:20::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.23 via Frontend Transport; Thu, 1 Feb 2024 15:25:57 +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 BN1PEPF00004689.mail.protection.outlook.com (10.167.243.134) 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:25:57 +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; Thu, 1 Feb 2024 07:25:39 -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:25:33 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next v2 3/9] ethtool: Add an interface for flashing transceiver modules' firmware Date: Thu, 1 Feb 2024 17:24:55 +0200 Message-ID: <20240201152501.3955887-4-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: linux-kernel@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: BN1PEPF00004689:EE_|BL0PR12MB4948:EE_ X-MS-Office365-Filtering-Correlation-Id: 37c8391b-d5ad-42cf-3cef-08dc233a16b4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LfZFx+ZKzEl5vH/lgZu+Aqk8R4hqyk8SaQjtQ3DEBVCpzSzkI9TASkYBjZM9LQ2TTcDLh7MBE8ewlMA+0d0uoUktbQj3MSs997O75FWtJ7qR0KryO7m4epKOkcpol9Or86ohKYgAP+LMgqccS9zOGtfKrpM9zLA9TzC51JRle8T/B2TNPTBAazyXlJ+NDCqSJmvHMDXIGMIxy9hFnsCAL3sIGeZd6WIDW+PM3//RkMw1rvkaEhvoQZblBKTb/te0r68+Ak9fF57uGyTVLH1cG2TiKKu6ucbEdV3NNeelYbmI5tHmQUPP70W5xqZXFBEwBP/srDFgmTFBoKu23ZF+2H/PBGRs3Qh64LeN8ztbFizm19yk+5vYTNFPPjwO0g2MDUGWxx+8ffaaTHd59PxL1N0kQkQiRllmiZMpGb7A7y2RMdcHPtmSD38WHs9kuaKq/5iPEzuGtpUZHVmPd9h1O4tbYqWzxWeDZ5btTaMVDsaxq7f2hcXeV1dde6btY/1vuN1h+UFp4jJCYjZpkSrz64qubuRk8Qf/b1IPhtWC/u8MYzROsk2qjIf9nhnQwp1bViH6WNni6zC0Qp8XOqfBabkpQKXtl7ywoachySvDP0UyreUw23c2Zr2I0+KmpNUPUmlvcs1VcsAU5mJZytbIb3JOw14PDj1kjAiX2z8vLs+Tol88IHxt6qM16k845tf1urhHNTLu6SQGyT3rL5oz8QSO0axw5E3hbq1WvAjtd/i6DTIBVC6Qg9ANmJSjHrMKXZSSfAjjoDBGe/ECxQFlig== 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)(4636009)(376002)(396003)(39860400002)(136003)(346002)(230922051799003)(186009)(1800799012)(451199024)(82310400011)(64100799003)(36840700001)(40470700004)(46966006)(41300700001)(5660300002)(4326008)(70206006)(2906002)(7416002)(8676002)(70586007)(8936002)(86362001)(83380400001)(36756003)(316002)(54906003)(6916009)(36860700001)(82740400003)(7636003)(356005)(6666004)(478600001)(47076005)(2616005)(426003)(336012)(26005)(40460700003)(40480700001)(1076003)(16526019)(107886003)(134885004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2024 15:25:57.3722 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 37c8391b-d5ad-42cf-3cef-08dc233a16b4 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: BN1PEPF00004689.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4948 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789710843783183927 X-GMAIL-MSGID: 1789710843783183927 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 --- Notes: v2: * Change the status attr to be u32 and make it an enum in the yaml file. * total attr: u64 -> uint. Documentation/netlink/specs/ethtool.yaml | 63 ++++++++++++++++++++ Documentation/networking/ethtool-netlink.rst | 62 +++++++++++++++++++ include/uapi/linux/ethtool.h | 18 ++++++ include/uapi/linux/ethtool_netlink.h | 20 +++++++ 4 files changed, 163 insertions(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index 197208f419dc..24b2c8dd86df 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -16,6 +16,11 @@ definitions: name: stringset type: enum entries: [] + - + name: module-fw-flash-status + type: enum + entries: [ started, in_progress, completed, error ] + attribute-sets: - @@ -942,6 +947,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 @@ -1693,3 +1731,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 d583d9abf2f8..e73149c66620 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -228,6 +228,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: @@ -274,6 +275,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 @@ -2004,6 +2006,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 =================== @@ -2110,4 +2171,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 06ef6b78b7de..79041bdccd61 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 3f89074aa06c..44e02533d01d 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, @@ -976,6 +978,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 Thu Feb 1 15:24:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 195364 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp234236dyb; Thu, 1 Feb 2024 07:31:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IELe6SDrE44Sk3VALPdBOQo/3N0/beuWH9rmLNhiW1EIce2y25E7IrceHYAPDIG0BMIADIa X-Received: by 2002:a05:6a20:3f9f:b0:19c:b3f9:2999 with SMTP id ay31-20020a056a203f9f00b0019cb3f92999mr5134186pzb.27.1706801490364; Thu, 01 Feb 2024 07:31:30 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVHQZfFkGBr5YC76MY8Iq1eVS7ll9OLMk+Oeb+dNRSAVruLFd04VWoJBsRxQctMH9hXnHdSNjUfdGPY3NR3pobMW1NhQg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c19-20020aa78c13000000b006dfe50c6c86si1988737pfd.212.2024.02.01.07.31.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:31:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48400-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Ju5itGKz; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-48400-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48400-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 91D7C28A6A3 for ; Thu, 1 Feb 2024 15:27:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C91BA15DBBD; Thu, 1 Feb 2024 15:26:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Ju5itGKz" Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2043.outbound.protection.outlook.com [40.107.237.43]) (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 B3C9477A1B; Thu, 1 Feb 2024 15:26:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801170; cv=fail; b=Q9IG2UA1AeZn7uYq2HKxtXpsY/4q/TSXZiwNdNhrZoP0D5XpVNXdotO3c4iH5n4ZORj2nEeRfmkD+4RawnWM2Gwzr9fPPaf9acefOWc/Nohtlr4rBRaFNjGvPcyLvQYgEGlmvT8bLEaGqUHNDL8L7clfi4tqga/msxkugrbeFWo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801170; c=relaxed/simple; bh=TBSwkPTQP40RZC5fqHwDMYBnRUPtFEibhFzzRGpPCHY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Tt6YyBloWVQ2WTK7wGwlxQE3X6yWk0Vq8/xHGxUK2J1mvfCwNVUZb6G3Da7Te2NulNzP+fMdiEHB0+JumQ+ZKgNWexSqfc3VtwS1SZDtx4ARf55d7jxY7RI7r8TI5ft9llplcJ7DKEBbh1NkKiO8uhVuYbVBfb6ACZ34aBlT8wQ= 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=Ju5itGKz; arc=fail smtp.client-ip=40.107.237.43 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D6KBCbcarffQzKAj/Cjbx70zqjyu7gi7VEk6rpi0mqzNqGVsawEsDcyFqP8flOdabrRHBMX8V8yPEcoX+Izy37EOlXgoRef5XFpMcZou1wF2vpEPZf2Gw4RK86m3Og4k18TMHpxHiYtrlzJy4wzWl4Qrt/PkZ2cjYFgmJPMQ1WTxlUZxTOfmvBdj8SU04cygoaQOEOsFGhrzyaU5oKwUOp0VGPns/Bs57pMyGxoN/n4CHhQ9IywuX0CKDmaKpeyWYY3t/OHwdnsf4Tc6E6KSvF/YeTDJ9d+BsfSgqDl97H2GGf/m3VVGm3OsL8YkEC/z4LKM3nxgu2x0GY5NbZF1iQ== 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=jWPDCsYso46zBksEAdJqyXz6pkKjks9CRjCua79qY0U=; b=JDY9rsC0Tm6pQj7y8rjmMj2OWHIGTtWlkMuZFEVT1Ryi59Y0N4YOQCvNcQ/uv1i7bYyIW3/ND0yThF4lAjK/3wHaZpywWpPDaYqtbtztq1QVA4g9Wk5ZHUY2kqHqoIHkFtAXd6YRrcnen16ztuuRCt/HWdtAQSNuGc90i9DdM2Dx11hra8cmIr1qSrCpNiXb2xi4ynX8yaV22XIYZvVBTpZdxd4/0zP3DhHiBZMHtRX/CLvrr+GkvY1J8lFO2huaVKDHMaIVGFyZci90pVOokcWiaWBdca3WRGwv9opC56kWbOXnvj1SeNw5ToF2hKhI5BmT2zSD3jvMQssr1hHcjw== 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=jWPDCsYso46zBksEAdJqyXz6pkKjks9CRjCua79qY0U=; b=Ju5itGKzH3DraxNI/SpxSZXCSE6bCzNET4rNDJZTM7c4anSfM0VHZn5U2HT1cP80p9u9ag5cSbS/zJZI8gx8ixTIEhcoK6miYDHjqA+3izmRxqlPQzGD2TQiGbQhnN3kakPxGgcwG0tPpdbRAEOmrNu8WpS3lV/9cJvZ5iKkuAaqemoK8gQCY2IRaRCdRGjqZ4iQkIWBfxsjXz7L+Ts/9F+yM0vBtvAue3GUkGGoIUwiz1RgOxzzMOPzcY+Wv/F3CQdFLA4hKqpTLmgsDd6om8lDveS8L66DLf2vtmxia7qUyJqj/lSy4o2AOn9vKijp8mEB9wEOzFty/inQwCfsUQ== Received: from BN9PR03CA0571.namprd03.prod.outlook.com (2603:10b6:408:10d::6) by CY5PR12MB6647.namprd12.prod.outlook.com (2603:10b6:930:40::11) 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:05 +0000 Received: from BN1PEPF00004685.namprd03.prod.outlook.com (2603:10b6:408:10d:cafe::49) by BN9PR03CA0571.outlook.office365.com (2603:10b6:408:10d::6) 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:04 +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 BN1PEPF00004685.mail.protection.outlook.com (10.167.243.86) 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:04 +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:25:44 -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:25:39 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next v2 4/9] ethtool: Add flashing transceiver modules' firmware notifications ability Date: Thu, 1 Feb 2024 17:24:56 +0200 Message-ID: <20240201152501.3955887-5-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: linux-kernel@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: BN1PEPF00004685:EE_|CY5PR12MB6647:EE_ X-MS-Office365-Filtering-Correlation-Id: 9832897e-3666-44e7-9866-08dc233a1b11 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +8MptD7/NXG7Ij1wCuIc7z8bOh+Yfw8KiRwd+/+MJmnw1hcU8KqcuAFQ25bAw0bXFbW+uLP7yW6ui9m1gsb2Tdc86Hthn65cxJqJshd5N8QBjQUuiYYOsIUs+UjJg8qb5XzePaVas/0UC5B6CAWFSXyyCnIpDU7CWe7CrcUDHHsXY7aH/8j4z4efdao+pYkeifq0hl5oNojOyf2evlws0ehhOlhXh1jEZrLQdGi3Fm6Om2D2ce6dxp51YaK2B59MPl3Wo25S5Lh9JjBWc4Nayt4i6amV5abJQ/kOALuW6hbjJpM5Ws20RBo8Qev2YRqIhCChXAD9lZz5wzbY3RNJYtEJMmImvJ0Ixt61IIStWMVLbGZACc9NHarLEUzLNr/8awjKDRahSL4GMrYjynWot+4Q0Ljk07j0vduclPP9SBWdOGavOwwlH5/l6d2kxb1unKkbD5hKc9HyIUnlecf/aC+Q8dO8EVRfRZi8y/pvbubaYxLJxvkbRNaZ3+qTv5hbj2hAgvpN4q7WzB/zFDRfDUoy5AKwod0bacAqXFs6UdiPkFTyr3XQHavBKN1QLDCZZR9VXFD6/0Xybzcisk15QrhFIa1ZCs+tNX+JLQ8W9we2WoQTv+YOy+u4IqrsfU3Owmx6a/ghbbCxLq54cBUa8F33C8BssKrQCJwtMPYsOQqp0hZiJSGi28rUYAMYvzY3CwF9IjYGs+WFgmPUN+RgpAc2LkMjAygS917WGUmht1aNzNaZFb/+A3xlI0+AKjYS 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)(39860400002)(396003)(136003)(346002)(376002)(230922051799003)(1800799012)(82310400011)(64100799003)(186009)(451199024)(46966006)(36840700001)(40470700004)(107886003)(41300700001)(2616005)(426003)(1076003)(26005)(16526019)(336012)(40460700003)(40480700001)(47076005)(36756003)(36860700001)(83380400001)(478600001)(6666004)(7636003)(82740400003)(356005)(86362001)(316002)(5660300002)(2906002)(70206006)(70586007)(54906003)(6916009)(7416002)(4326008)(8676002)(15650500001)(8936002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2024 15:26:04.6949 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9832897e-3666-44e7-9866-08dc233a1b11 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: BN1PEPF00004685.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6647 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789711079436133726 X-GMAIL-MSGID: 1789711079436133726 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 --- net/ethtool/module.c | 76 +++++++++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 10 ++++++ 2 files changed, 86 insertions(+) create mode 100644 net/ethtool/module_fw.h diff --git a/net/ethtool/module.c b/net/ethtool/module.c index ceb575efc290..09cf11564840 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,78 @@ 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, + const char *status_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..36cb0bc85526 --- /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, + const char *status_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 Thu Feb 1 15:24:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 195370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp251818dyb; Thu, 1 Feb 2024 07:59:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IElIfKo6RfW4vunsQIFL8VMF7UXIJlGqoaUOF41xSjYuWagso7+LNMvfFLBVi3c0xxWVY+Z X-Received: by 2002:a05:6a20:b9e:b0:19e:3096:ea24 with SMTP id i30-20020a056a200b9e00b0019e3096ea24mr2485441pzh.37.1706803141325; Thu, 01 Feb 2024 07:59:01 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVsTVL+wAv3lrcfKB2+dJ+DmETNitEliKaWyl1sZ8P5FnT1OReBMYZ7y0ZfOkKCTvUOolbAYi6JJLXhEmPNtlVuUldXyw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q5-20020a17090311c500b001d921bbff0bsi3698plh.78.2024.02.01.07.59.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:59:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48401-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=RoxSgqw3; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-48401-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48401-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A0F7DB233E4 for ; Thu, 1 Feb 2024 15:27:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 511AA15DBBF; Thu, 1 Feb 2024 15:26:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="RoxSgqw3" Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) (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 3E38E78687; Thu, 1 Feb 2024 15:26:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801171; cv=fail; b=lcBC1y8CrcZR7mf+qye4fYeNUGj7/N4plHPmuettLuvRSk09hP933eXJ01ZdlWnxuxhSxmo0PsQ1WFXHhXq5iPonfb+PfPeBw0KzkeJvwfpT63fXnppinqO5yJap+cvIkpi+4P9rqBG1zyG3M1lC/CuJXGOR9kVFdMVMzgU0yz8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801171; c=relaxed/simple; bh=1eETqnIZ+N5byJgyBmUWyK2NXqBoPQv2UGjGXOA6N3w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ue//++FKmbRrLIGR2Rwbqyp4s1Ez3YEZzI27MhlUMzromE0xsdGGd3lbv5lxPN57wfv6+DxBjPF9GKA2AakjGDh2EBI16lMsYnDj09tKWBYD+jffUHfKQ3MfGfv8zNHVF5DKmm6h6qS/L5YOWkS+7+c2S+FpP11SghAIDgvpHI4= 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=RoxSgqw3; arc=fail smtp.client-ip=40.107.236.41 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fnltIAUxoaqX3ht88dg1oEy5prV9d7VvtiGB/U1+SyS/HqZ/u81P379yUvsXrI+ZDNqyOxJ4AjcN/x+nTydoNqZiI76NA7yTcnoGNw0tr9HroSmVMOWcdhu3M9r9hewrOc4TOX4iEYKy+2R9JecEJHfzEogIbSmDwh/IwI5DZxMm2eJ798uq0LpvEmKJJJdSzMmAqcn7w5WdMx4Nl+SyYf29Wz0EUNDwGWsAyU6SK3VO24pIexlkEiM2M3AV7vzw9iTtHwwTmR4zzoGmfzKEipRIWVDIQRnOsjg5Sq+JyFso0Za83QzzkipUb/x+bt0QQGChGv5xqmWiQrvNm4HqxA== 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=9hO50i8u3SENJk4lf3SwUSfxiU3EEL2Ohm8aDjO+dUY=; b=fMoPQiQsAA+3S8k8ZG8Xil5b8ujPFdZ5zVbiVuK1XAotBo4ddYhxavfHD4VMMPw1dFehYpTvmpHXPG8iWh69HuEUqvDWxwm4kJ3i5mui2YJMWmRS9N5h/XgaepPXFjYwD21LDF6w1E4I0XEdsmrZALQouIH9Iy37rn/pdReI02WawFmzjsa5ppOy4v+Sk1PvxBlVUwAZRuy5BYhIvSdMThRbVXi0jsmbpKkWKGCfzRaH/DLeXSpHWjkzxh7SnY+8WCY3UpnSq1e5aeyFQCINeCw7O2q7W0QM6c1Ltz/KkHTgNjovzu1zh3LG9UNTMcDg3R1IAJRLajcc9yK0uxDuLg== 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=9hO50i8u3SENJk4lf3SwUSfxiU3EEL2Ohm8aDjO+dUY=; b=RoxSgqw3qKV2Hi6jRwvvofp8YsQCi0JGbwlYRQmUzXW8eLjTShmRF0ipjPUpKNV/s6AYyJB8ArcUG1h1WaYdrBsu9r3l5LuyKmXMtm1xdwQGwzw52Ltrf6GYS+2f6YBGWQe9XJQ5VQCEDTthlsn4jM1cskS/6McapMJYGMqotMGCtRH82v99CDa2pWU0Wqw7S+yXc/lf59vtgPpdWwXU77RatmLvdQyaoXexBDT6L/k16yWP8rUTeNdG6dVJOYRDhh9vqYzZSxfRGhwREOuk4+pqg/3cGoc+LzciqkTS645PzIFjMlhvcfpCeHBW3lmdgrcWrTVj9nAi4293HrNzEQ== Received: from BN7PR02CA0026.namprd02.prod.outlook.com (2603:10b6:408:20::39) by MN2PR12MB4078.namprd12.prod.outlook.com (2603:10b6:208:1de::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.11; Thu, 1 Feb 2024 15:26:06 +0000 Received: from BN1PEPF00004689.namprd05.prod.outlook.com (2603:10b6:408:20:cafe::bc) by BN7PR02CA0026.outlook.office365.com (2603:10b6:408:20::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.24 via Frontend Transport; Thu, 1 Feb 2024 15:26:06 +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 BN1PEPF00004689.mail.protection.outlook.com (10.167.243.134) 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:05 +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; Thu, 1 Feb 2024 07:25:50 -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:25:44 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next v2 5/9] include: netdevice: Add module firmware flashing in progress flag to net_device Date: Thu, 1 Feb 2024 17:24:57 +0200 Message-ID: <20240201152501.3955887-6-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: linux-kernel@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: BN1PEPF00004689:EE_|MN2PR12MB4078:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f1e897e-33a1-40cd-1810-08dc233a1bbe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1ZA0gpv1RBE9o+viZRXReSGfrfrAu09SkHUGVEjq/Kp9j1RwCYsgwD2pZjpJScAdfP52/W9IDTiHZmWIJzm4VHWGtcgAr6qA9ZgntUt+R5XEEPVAk2SP2tsK7PuPnTxk+OXSJsjm71RruWwW4fYlcsXLB1oPImDEia/tvZdjCv+kfhXatgIIqT2dK+sB73qKWkVWtDCpO5oDahPt6aUk3XzlfYHEn8z0aw0os8PT0B2Ifm4RDxh096ctzLGPxr3ldxY4Z9OCRjpkDvOiAR+ZbMU9dNfR1jzwFrZDYj6ea8fxQu+6YdXY1v3o04iKEFbgmAIRhhIANE3BZmfnuAjj2DDsaZT5FNF4650CQ5dEqAXny6GMgOuz+Av1pBJqENXiAXEoUnw6EAQ73tSZT2s/YuHBcW2CIK5EEgxouBPgn6P790tIdeeItxw2CDJ57pV9TESzstrcEmWSUHcwhzeu8WsVoy1058DpkH1qiofuZiI/y7TWhCcX71DltXLFtK8QfWHfTMfW0J0AGQmmY3JjdzcFxtyDDKCLq+F9bGw6ubivYqFSs3zD3NlxJWJzuHaAyju372//iiDlLkqC87svk07WyVnPznQfZAKw3JgwZ+llwixjhi1O3CmziF2eQoJtAwCD8NeiLGfiTipJGJZp3O2Rw6oEfW76Q75g7y8Pue1YO0ci/rEhFgJcsthzzLV8pUxmFIGrFSuL1Yo35CH1w2PQUjy/LAxZPnqqQvwrWopXAonkD7NeZxwJZo+TwIe4 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)(4636009)(39860400002)(396003)(346002)(136003)(376002)(230922051799003)(1800799012)(451199024)(186009)(82310400011)(64100799003)(46966006)(36840700001)(40470700004)(40480700001)(40460700003)(83380400001)(36756003)(86362001)(356005)(41300700001)(36860700001)(426003)(47076005)(2616005)(26005)(107886003)(1076003)(336012)(16526019)(2906002)(478600001)(70586007)(6916009)(70206006)(316002)(6666004)(82740400003)(7636003)(54906003)(4326008)(5660300002)(8676002)(7416002)(8936002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2024 15:26:05.8254 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9f1e897e-33a1-40cd-1810-08dc233a1bbe 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: BN1PEPF00004689.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4078 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789712810520952002 X-GMAIL-MSGID: 1789712810520952002 Some operations cannot be performed during the firmware flashing process. 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 1845dd5043b4..df8937ead7d4 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2061,6 +2061,8 @@ enum netdev_stat_type { * * @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. @@ -2447,7 +2449,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 Thu Feb 1 15:24:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 195365 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp234450dyb; Thu, 1 Feb 2024 07:31:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IELR1whuVKRnajYa6IS8lp9wYY9Iv7wcAydeVkjDjVYMEpgFw0EutphF39glXlA2GvsS28e X-Received: by 2002:a05:6a00:21d6:b0:6dd:d0af:7e75 with SMTP id t22-20020a056a0021d600b006ddd0af7e75mr5031904pfj.22.1706801506628; Thu, 01 Feb 2024 07:31:46 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWssv72/WT4jV0uyTGLCswm808g47bnIcETYkc4dj4XC9CsG0QxxsIjU+ACGcyh4eM74ig+lgHVwNGzUyQUh1G7NMrRoQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z9-20020aa79e49000000b006de0dc47635si10555241pfq.268.2024.02.01.07.31.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:31:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48402-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=O9MLSFlU; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-48402-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48402-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A968E284A2E for ; Thu, 1 Feb 2024 15:28:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 046B3626C9; Thu, 1 Feb 2024 15:26:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="O9MLSFlU" Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2077.outbound.protection.outlook.com [40.107.243.77]) (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 C632215DBA2; Thu, 1 Feb 2024 15:26:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801175; cv=fail; b=YisqPPdvqNVJjumwhX5Al3gRHHV8I2klA3jZUf3TDGO8MoMPS7JeetuFO+OQN3uJKCPnvrtyPOrZzeJMVfwDtIH3MwWMjcEsQPu4H/1MqQOid6ogJAogb7y7BbjQp7WQv5NEkvRqgeXQQnX9swEYHSRa7/566mdh4MKHkP+cQHU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801175; c=relaxed/simple; bh=gFnVtXXhF2E/aAopuLCHH2MMPH3g9JGW3jTst6Ba3l8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lk4iTzuFZ2cntrp9morNNzeFAUSIWSMbfkhNk6HnahPt2jK73t4R1TFcExms7i0elYbb2DF8nnw91+R9zDVRTxmdebnf5G8SLF+mJIo0llRgvzXnxcySFXj5YM1vjLgR2QyhpOtOS9eADKWHdFDlp2sXljfTH5VwTFUeVjiZAkw= 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=O9MLSFlU; arc=fail smtp.client-ip=40.107.243.77 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YsYfsKnvudhGJdlUmQRd64QL0xZiEhtl4OuBTYFsymMZBcpqfp3O7a2AAa7u/Y1ihctkl1nj8+woajUFgsWieIpHroXWT5ywkatK8Cl7KGnwGVcBKz1SV6vzUtaoV2NWSPLCOOdb+apKvVxbZssiQdD69nhBSvNCrRF6ZU14Q1hyqn7bLFiMG1t3LFtHL8xowGhSBgICCUIhh8Nmf28Rsm9IB3gP3O+Z30Hzn9Z+PK5DiZxNtzwNTLplWLSf3/ENfVXGeRBssaL4IoEHX3ZnuvIFQstWIlvyK2FYgFmZjLwiOtgldVVOl4sqHW9jldZ8ZKsj1cNh/PP8Fj+TXHwayw== 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=qbjvCQOZtFbYLZNNg2W7tfykK7mijM++KCZPUQhNBpo=; b=fLW6l7wEvr3zEIgiXmu1uSQHDGaHL5JSM6OBAxjCHvTYBAFsxnkg/0Vmooexd9vESQa3UoFtk3pwo3OT7eMEFH8qJQZUu7o/QtSD7zHyrS3b8pK06FtNa02ITsKAew/EDMLxrDP2fD47Eo2Y/x7IAe96MrAZUvZo6qvOSsU072wCcDZMM/PKS7pDIR3X62nhfLQ4MLsQ03g4pd5TqgdeSQIhmz64YLSwyt3BIJMBVNCehhilHTv+vq8Ak6Zb+CtiPdW0Zd21tRX1gGbb+2+YHYPfpfRJO9jJxWxXCaOAcuzFzrnVcPzz44c61AOr/3EFoWqL535uZjqfwXRDyYuGxA== 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=qbjvCQOZtFbYLZNNg2W7tfykK7mijM++KCZPUQhNBpo=; b=O9MLSFlUzxwS59bwfNJWyC4F93CVMgZh590nz7CVXajOpxctE7JARDiNkfB9cXjYDg3bBF2sTAJB2NV0lYPBCv0xSaAD5iqIIdV34zRD5iesc19zO27dnXxiEoiA8blNlNP//cqND7NIAaeW3YavqWVNgqZa2V8D0KqyNItkz9hqszvKcYo29MGqTGcgY5Mwrc/cA6xEP2OVwP5HFzhE0fmcc2sRsGxczTup+o7fJR3kIdqBlIpsik6IKNMTlAk8kY2swfFUUJtQ60teFqTWtVvhT4lZIq4wfdylSDPioZonJn0UKVWB4V/Fm7fnD9MaY5nBGBvnYkUW45afEoP78g== Received: from BN7PR02CA0028.namprd02.prod.outlook.com (2603:10b6:408:20::41) by SJ0PR12MB5633.namprd12.prod.outlook.com (2603:10b6:a03:428::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.24; Thu, 1 Feb 2024 15:26:10 +0000 Received: from BN1PEPF00004689.namprd05.prod.outlook.com (2603:10b6:408:20:cafe::11) by BN7PR02CA0028.outlook.office365.com (2603:10b6:408:20::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.23 via Frontend Transport; Thu, 1 Feb 2024 15:26:10 +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 BN1PEPF00004689.mail.protection.outlook.com (10.167.243.134) 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:10 +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; Thu, 1 Feb 2024 07:25:55 -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:25:50 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next v2 6/9] net: sfp: Add more extended compliance codes Date: Thu, 1 Feb 2024 17:24:58 +0200 Message-ID: <20240201152501.3955887-7-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: linux-kernel@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: BN1PEPF00004689:EE_|SJ0PR12MB5633:EE_ X-MS-Office365-Filtering-Correlation-Id: dfc02ace-3ca2-4b8e-5dac-08dc233a1e4b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7tAOVDV+HwDbeMGhwKrvNCNFhE04wlky0TnM/hvTdq5J/cbay5NayEuaGvnXhthk4nWUk8Yjnj3Z6bmT9uynuANAOGFIkFV/Vk3kS27n2LwG5IOx6oy13NaB7tJBXBdS7dwMrPGU2BQ+QCGpTTrVMZb3n6E9Vj+zD8sr9j+gAZI+IiLqSmecK1+3V8Rl+O5h/hy/t+56wRg53a2HGOBU4/+1j4fZEalaXvHTXzJvAMR2YSHHcJeK+vxEkh3EwlAoLO5ZLPJQcA8VodjN4zRxJX1QEbJBjZPckNqM5mMBSvjwilzGuqcdJghG0+8WtnJrw/f2aUJEKNqmySPMr6FYyrz9JHC3VxziUkhAjj/TIyTGaVi12kG8z+1A/79wPqZ1eIzuxH7Y/MBYDxmLQuVEPxlVEUApSrW7g2icECTxKObGPAQLZU+UlPcHBQamnit/0A/WpVQ89HJ+a/mB3f+4Oju/A7NpXoH5uWV+2zLVW5+s4Yv5zsL6fgMi++G+7gWMMGXKVPwzL9TqynsFAC57+O5gYfIewQh2DAqduAqqPWzRQiuHe3T+9RYReQbPmuQeEesFz9f5b2QcPpce8Zth/CbRLYnNB7u00m6hQB70CdaRZ8unFfo/4RFg29SxQ8mEeQv0wOa4fA/DPKNn9p4pNCNlBV+MDLOTBF0mPjBItIY5GYlkTJxehEVmH/e2TajZlM4yqKrXTHNCCGmOeCyxlXxdT/KkmNo6nyahv1xCyDX9l67PxGkUcAzNSpd4xn2W 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)(4636009)(136003)(396003)(376002)(346002)(39860400002)(230922051799003)(1800799012)(451199024)(186009)(82310400011)(64100799003)(40470700004)(36840700001)(46966006)(7416002)(70586007)(2906002)(5660300002)(8936002)(4744005)(82740400003)(86362001)(36756003)(41300700001)(356005)(478600001)(7636003)(1076003)(107886003)(16526019)(36860700001)(426003)(336012)(26005)(2616005)(6916009)(47076005)(316002)(8676002)(4326008)(70206006)(54906003)(40480700001)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2024 15:26:10.1067 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dfc02ace-3ca2-4b8e-5dac-08dc233a1e4b 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: BN1PEPF00004689.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5633 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789711096499005708 X-GMAIL-MSGID: 1789711096499005708 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 9346cd44814d..df2eb988854f 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 Thu Feb 1 15:24:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 195361 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp232452dyb; Thu, 1 Feb 2024 07:28:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHi7Lj9dY+JNdjLmr6+S8tbnZtsIEntXsBLQjTV7fhNUAYRPWOlrhOvcWnETQlxEFxWLhJT X-Received: by 2002:a17:906:3d52:b0:a35:d69f:e4e2 with SMTP id q18-20020a1709063d5200b00a35d69fe4e2mr3719662ejf.30.1706801332608; Thu, 01 Feb 2024 07:28:52 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWHM4sbG7DiegfAG1kuns6Yk+DRxZ8I2rxeX9NMhYy1H/nDDEvSz4FU16C1TQIvl9JGn4tnE4XpmIzv5OASOJUuo+BkqA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id o9-20020a1709062e8900b00a36c68dd451si589702eji.734.2024.02.01.07.28.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:28:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48403-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Cr4FQKug; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-48403-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48403-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DC5081F24292 for ; Thu, 1 Feb 2024 15:28:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A30E77A1D; Thu, 1 Feb 2024 15:26:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Cr4FQKug" Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2043.outbound.protection.outlook.com [40.107.92.43]) (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 32E3315DBD1; Thu, 1 Feb 2024 15:26:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801180; cv=fail; b=pEijO/0I+0w9qIGJXKgXh/KkcbjohZohqeA0gQZdoxvV7qCGcaiYfjGbSap35+KBj2KbvPxaiD3U/bDeK7wsvq0366U4mG3WejGk5gXDrFMAxzjGarexIoqm2lBDZ20sU98uD/S36+fkLzGGcCP26OzvyM3O8uIyV7VXreID3TQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801180; c=relaxed/simple; bh=KRsW51WHoHzRoP/Dc7cYbif6ROAIbWURK8LD3KPU1DQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jhOCbEHJU4rV4kPydpSwGykOCxWsYvAbu6sOEEYjqy4IAEw3EGa8XV3xB7WEFAgLvKKe5JY5Ya/lzM3ojvA5yLVZhGbLoZ/BQ0UKUAPXpsVROlX9KdxBBrWzElo4ObXv1XvGJCZDeMkiV6IKrhUG+efujtbVXBTPZOhLfkFtRZ4= 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=Cr4FQKug; arc=fail smtp.client-ip=40.107.92.43 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nqz1p5qcU/h5H8FbbOuBZh/5MmSSaHeBWgYp39s9+EaPRLyjaIQvSrQlNrg8pQuQIw5DjW541Y7IAXHa+wB5s5QsNgarH9x1M13wxozDOcz5Q/MTl0NOyBjw/negWBSJTgtAKgBHU2R5uVeML402gzmMkc265vPmMlizO5Jj/poJjmgBjyrS0OPaBL91GbP3T8fTlKY+sUCxhZzp86o5y59NcnpWxFNgxJbB7s+jz7QthpPssq+7SIfOzz7+IXONr5mG/dMlkWSaIt3rEbpBqasdEtGP7l49LNfG+WgV5mm/IEe4/NM/CB2T9ca/yD/8M9QR447fpQOOHOuzO1N2bA== 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=NdUaByYiqJVd8YhP3GlcRJMw6091FM3fcLEoqct3NK8=; b=F2RngZSGKtuKqcRjfdXvzFsSz7tOqza6tW3fG1gZ0hoC6OqlizcYrqinUE7sZ5h+9UUzl4UDTnOkm9iuaqAevJy4aeqQfZf4RS2ZpXDal/NvBLGVOH2g2XjnMYdYkTf9EXEIjJ/P+AnqydwSD7YPzMKtFoEFgAY6Me74cPLIy79MHjCXEidWvq9qkGYHbZJEhkVTP/YQSVR1aIZc+baFZ/fD13ZyZowzQ2L6osrzKp9bTecRA7v/QwVlCbVqMLT8v8It4Kd3VliSr9KTrKYnXd6qY4e2WNe1zX0kQaTJzMEtXCXgDBq0LHgB93UfWLDSAXG7NAijVsttrROrPG//Rw== 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=NdUaByYiqJVd8YhP3GlcRJMw6091FM3fcLEoqct3NK8=; b=Cr4FQKugZ6VDsRc2r3EK+xSvNb/R3v/O8gbxzZ+nIv/B2JD5pVzNK2aXPJzz/onHNsYxy5PW4/BtOohQgHrfyynQcn2NFf+td4U6IpzBbMu7p8U6ZFQakHO56XTi6kA/noDGt5uvUC3fu2nVAG/zFYkG/fY0WceyJ9BNtxdIwTC2AYYMs6K1mjaUoiaunowM225F61UA+BTYEC+vXto6JyHqi4+AWz1wWbWb4eYAB1XFpTvt0wMXO5ud/X1aheBmZVJ8shL0Vf2pAgUYcw9Z3UPMWZxk8o4Tdp88wqp7Mh6+ScLHxhsDSsXjHkWkOlPMsXOa0Dws8BCgMoLHdYAOqA== Received: from BN0PR07CA0023.namprd07.prod.outlook.com (2603:10b6:408:141::6) by SN7PR12MB8789.namprd12.prod.outlook.com (2603:10b6:806:34b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.35; Thu, 1 Feb 2024 15:26:14 +0000 Received: from BN1PEPF0000468C.namprd05.prod.outlook.com (2603:10b6:408:141:cafe::a4) by BN0PR07CA0023.outlook.office365.com (2603:10b6:408:141::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.23 via Frontend Transport; Thu, 1 Feb 2024 15:26:14 +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 BN1PEPF0000468C.mail.protection.outlook.com (10.167.243.137) 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:13 +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; Thu, 1 Feb 2024 07:26:01 -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:25:55 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next v2 7/9] ethtool: cmis_cdb: Add a layer for supporting CDB commands Date: Thu, 1 Feb 2024 17:24:59 +0200 Message-ID: <20240201152501.3955887-8-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: linux-kernel@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: BN1PEPF0000468C:EE_|SN7PR12MB8789:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a365a53-6234-45f5-f3e1-08dc233a2081 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5sJSQYtJjFTnEYbNuLtZ3w8w+hm+2isxnmggzQ43c35Xq+nhGLpP9KoiNyWimdMvtZLWmNgxMR8PJkjLAzqJIzzf7ld+QJXfKj/y6XdOkpABe2fpuWrN19+SWvoI5Nrh3fdXSZSRI6tCcVw7YL0dXmKFXLo34/zepQZ1E+MymHMLISNvEq1qW+j1AyFJPFbiemJN8jtcO+7+8zCMYP00DLxt6J/QhU/GZ2Vjh6QGatmA705DxSujHEcZMoMZEXsxJnGqPdh5BT2DkPc+rtQcoqM0fWBFQFvCovOa+2IB2FG/1egxSUaQd7n5CBY7zzbK+oMiSZTEVBcb0nG0kkQZxPpwv5OlMNarn0fYYNaZ5JUNcFJgShqCMh0ZNNvnAHL1VPopZ25mIYZjLaPfqR+G6RoLjP08M92vsZ05VU+V4ZZcvSS8DaJ19dBXxOrXcGzodCNPFuZs6V0fzZ3+AA1zXfQnBrT9fBCrEqUuSDt8asqjVcd0Q/CRHMzy3KuQO61I0zLkupMvfB9e2yHyzSE0UwK+QhS6AlUnHImYCntcBLxQkYMHunYSpLchQ6sifeJl0As40Hj4X4+q8DQaAzDVCWYKBEX/JAc+9u1scUrM0QwlJenMIGnWaVStUWjqAvFOBbGL8upp9+/PuVeN1SDFrTfJY8tnaGJSj4Z5VaRt7SLPM24jzW+5D1E+kzhGhjHaii10iuI84bNPwkYzosvuXgtBIBKrGtzvZ/EMUAmfxZCnoNH4Rhz8up7zvuySoGpm 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)(4636009)(346002)(136003)(376002)(396003)(39860400002)(230922051799003)(186009)(64100799003)(451199024)(82310400011)(1800799012)(36840700001)(46966006)(40470700004)(83380400001)(16526019)(426003)(336012)(26005)(47076005)(107886003)(2616005)(7636003)(41300700001)(1076003)(82740400003)(5660300002)(8936002)(36860700001)(4326008)(30864003)(7416002)(478600001)(70586007)(70206006)(2906002)(54906003)(6916009)(8676002)(316002)(36756003)(86362001)(356005)(40480700001)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2024 15:26:13.8199 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8a365a53-6234-45f5-f3e1-08dc233a2081 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: BN1PEPF0000468C.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8789 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789710914187856994 X-GMAIL-MSGID: 1789710914187856994 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: v2: * Remove kmalloc from ethtool_cmis_page_init() and use the local payload for page_data->data instead. * Return void in ethtool_cmis_page_init(). * Remove ethtool_cmis_page_fini(). * Restruct ethtool_cmis_cdb_execute_cmd() to align the page_init changes. * Kmalloc the CDB command response. net/ethtool/Makefile | 2 +- net/ethtool/cmis.h | 112 +++++++++ net/ethtool/cmis_cdb.c | 525 ++++++++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 10 + 4 files changed, 648 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..06596ae749a5 --- /dev/null +++ b/net/ethtool/cmis.h @@ -0,0 +1,112 @@ +/* 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, + u16 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 rpl_exp_len; + u8 flags; +}; + +/** + * 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, 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)); + +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..b27b7d8e2375 --- /dev/null +++ b/net/ethtool/cmis_cdb.c @@ -0,0 +1,525 @@ +// 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, 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->rpl_exp_len = rpl_exp_len; + args->flags = flags; +} + +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 = {}; + 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; + } + + rpl = *((struct cmis_rev_rpl *)page_data.data); + *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; + } + + rpl = *((struct cmis_cdb_advert_rpl *)page_data.data); + 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 cmis_password_entry_pl pe_pl = {}; + struct cmis_cdb_query_status_rpl *rpl; + struct ethtool_cmis_cdb_cmd_args args; + 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, 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"); + 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"); + 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 cmis_cdb_module_features_rpl *rpl; + struct ethtool_cmis_cdb_cmd_args args; + 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, + 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"); + 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"); + 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; +} + +#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)) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + struct ethtool_module_eeprom page_data = {}; + struct cmis_wait_for_cond_rpl rpl = {}; + struct netlink_ext_ack extack = {}; + unsigned long end; + int err; + + if (!(flags & flag)) + return 0; + + ethtool_cmis_page_init(&page_data, 0, offset, sizeof(rpl)); + page_data.data = (u8 *)&rpl; + + if (max_duration == 0) + max_duration = U16_MAX; + + end = jiffies + msecs_to_jiffies(max_duration); + do { + 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; + } + + rpl = *((struct cmis_wait_for_cond_rpl *)page_data.data); + if ((*cond_success)(rpl.state)) + return 0; + + if (*cond_fail && (*cond_fail)(rpl.state)) + break; + + } while (time_before(jiffies, end)); + + 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) +{ + return ethtool_cmis_wait_for_cond(dev, args->flags, + CDB_F_COMPLETION_VALID, + args->max_duration, + CMIS_CDB_COMPLETION_FLAG_OFFSET, + is_completed, NULL); +} + +#define CMIS_CDB_STATUS_OFFSET 0x25 + +static int cmis_cdb_wait_for_status(struct net_device *dev, + struct ethtool_cmis_cdb_cmd_args *args) +{ + return ethtool_cmis_wait_for_cond(dev, args->flags, CDB_F_STATUS_VALID, + args->max_duration, + CMIS_CDB_STATUS_OFFSET, + status_success, status_fail); +} + +#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 = kmalloc(page_data->length, GFP_KERNEL); + if (!page_data->data) + return -ENOMEM; + + memcpy(page_data->data, data, page_data->length); + + 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) { + ethnl_module_fw_flash_ntf_err(dev, + "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; + + err = cmis_cdb_process_reply(dev, &page_data, args); + + return 0; +} diff --git a/net/ethtool/module_fw.h b/net/ethtool/module_fw.h index 36cb0bc85526..8bbf13cea4c4 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 Thu Feb 1 15:25:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 195362 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp232526dyb; Thu, 1 Feb 2024 07:28:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDYI8jgH0V0HlBOvzbXoVcHtxDxwQu5W+Tvbu7qJmstKY5oCudxebO8Uj30+au0ZhLQDHd X-Received: by 2002:a05:622a:1706:b0:42b:e3ce:f43 with SMTP id h6-20020a05622a170600b0042be3ce0f43mr5620300qtk.53.1706801339590; Thu, 01 Feb 2024 07:28:59 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVR7hRKVA/HdFbU7TqTtUVbVJ72hPWz/ADLgt82u+hOId+8c+eLYBctbds61bzBiWxzSFaOCejXLUjsWflXvVaMBqvpzA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a5-20020a05622a02c500b0042bf8fce686si729513qtx.249.2024.02.01.07.28.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:28:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48404-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=KMZWcsnI; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-48404-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48404-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 54A771C26AB7 for ; Thu, 1 Feb 2024 15:28:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 938B3160880; Thu, 1 Feb 2024 15:26:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="KMZWcsnI" Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2066.outbound.protection.outlook.com [40.107.93.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 B753F626CF; Thu, 1 Feb 2024 15:26:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801184; cv=fail; b=d8JqF393jyVIXyNUBfzgeF+vtTi9VTnUXYLh9dsqAItFirQCt5Eeb7UVXueBPlAcq3MJ7Q+hnsFfZjNbE7KIs3S1zrQPqZTiJbFydaS4J6wB9N+Nk3P9VS9Hxymumi8alLqGTQzOUhe1h6gox1zEmeOJh7t56Fl7AYZvnMpaJMQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706801184; c=relaxed/simple; bh=58PhNOh5H8La0Q7YrOKUM7p/zhoolQXRqUYqmfCyYFg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u4NtpjvJlZCpgIaRmC4jeJY6Wd5wpZVN5TOKiZ+nkFnYQcfrIPyIUmcL0bL2fKd2jmaG9F4whvYZgTi2+Wke280YiL5wER/XqppoFQ/dd/sVDqIQse9nh1ZMKD1IeugBT0dVyta7wlSz2gfkYLjTJ6r5agPZ98rU55iEd7CfJlc= 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=KMZWcsnI; arc=fail smtp.client-ip=40.107.93.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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EzNQmN6ObUkIaFJ+Rbbcrz2x4Eo8G2+Edi2cOka9oG2GTgY6UoGdE/P8PTC+XWt2AKH9dd8QaXyvsW8Yxf4ktgNdQkTlAlZCMPtcs1+8km6HEIfOOj8b2B673SP/BmrcmBxaHemuT8dB0YCOH338Ref5cRbkZF+ZYhjJo30+ACzdVdYedJi5eoBso/u/uHSCVCmQZxh26abplOzsACDFjrHyG3YmUsK6thS0a8WVYbJGmJx5hB120ztArXWRuFT8bqXXxFbj2/eAO6UAtXMSkgbzkIC175ww7BbW3qiYTUecxyGnkb4j57Mb0Co8dZE0x2HL437BqcMVyw7pFq8Eqw== 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=9o8FRMTSt0O7uZLJ2VqR+gX4lLnudSO1tBOo/1740PA=; b=HApiq1r4cS7G0qfFU51erm7Yg9kEfEg9AK8eLVbuqLyJNgEXvQVJb9D5Bc8sEBga03wa+5Or+grYZZyTbER57Dheq8BeN/JeaOOaCPWgBPT+dcmDL1+Zumo/33DOfYftXob4nq9vnYZjsdAm8fLGW7V6W6Jzal3gpe3nOmLzMfuSwE9eFFW1RQSddfo84wDQ9axw7sWNan1i0BBg60guv7kLom3Ppz4x5ikPSBopATPaYKB1x+KyZ4jqMNobPp+LefWmNn/7jge5n+gMDycOJ+FPmckAWJAVBLLAfe6xuE9mAUEkC2poNmUCbus3D2zHYjaYDyJQxkBey7mmcSW9VA== 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=9o8FRMTSt0O7uZLJ2VqR+gX4lLnudSO1tBOo/1740PA=; b=KMZWcsnIeA9P15qIJbWLI+e2YebH26nDWgVUTDzQo72/HQ64UUAhc5p4qE4Urr0VSX3V3lerYVZPF6Xo0l/ckDZgdAPB/sFo5n1KtGLFN+Ii6FzDvw9K1Mrmw8yRGVXHANgQuuWAPalMkjIofmfpNjF64EkJLO16qUkYZXu43nG8TvByjND28pttMUjaL0rUO4QJ+csl+jf1VKyAg+xU/YVn+ht3CvsK3hK75YndXNyGlPDsO1mMRNajHOSlvJvytopfsrguus1pboTgBSZeyBq+hfPUWq4cHbuIlLFr6PVGutnU2BBXQF8KGOuenkSB4o2bAVRN4TqyybYbpeV1Rw== Received: from BN9PR03CA0775.namprd03.prod.outlook.com (2603:10b6:408:13a::30) by SA1PR12MB6727.namprd12.prod.outlook.com (2603:10b6:806:256::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.12; Thu, 1 Feb 2024 15:26:19 +0000 Received: from BN1PEPF00004682.namprd03.prod.outlook.com (2603:10b6:408:13a:cafe::5a) by BN9PR03CA0775.outlook.office365.com (2603:10b6:408:13a::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.24 via Frontend Transport; Thu, 1 Feb 2024 15:26:19 +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 BN1PEPF00004682.mail.protection.outlook.com (10.167.243.88) 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:18 +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:07 -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:01 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next v2 8/9] ethtool: cmis_fw_update: add a layer for supporting firmware update using CDB Date: Thu, 1 Feb 2024 17:25:00 +0200 Message-ID: <20240201152501.3955887-9-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: linux-kernel@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: BN1PEPF00004682:EE_|SA1PR12MB6727:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e168a9e-45cb-4554-1ee5-08dc233a2394 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eKYs1gaoFGSRP41DKCpNkfn9dSfrUig5uwrW8BhuQx4d6Z3aneGwRa2RJUDYWOJeanPSNg5++GwBEhj2yACl9iiE9EsnpJFdroUbK5tAJUDGVWFQkg/DlMY/s4gQP4WDXuvP7NQUYdrQavrOD+GClK+idISZy5FC9qPboCl2lNbX1ND7oR43jYyj8uUx54u+gmmv9KLSjcji8FSIQdwinXHm2kTV7eZ+OQ5ac7ekBQjZClkTag0h3FBymKhsJ8nrVAhXo2PhR/sHbz32dwP9UsftmR1E0eOqql0UgOk1XMxzHbZkH8q0UtAviW3YrBQPQCg0fFQJhGHTh7xopCOD8Rn1XNJokdd5sGlfDncp7nWyIROB7adhXjF5SnlJ/pcrkftZfSYk/nQK4qzRne5fK/tj3S0SXxGZeHk7rsbZ7fKi0CkqD6XbdBi+Zz8qXHgv5g2sJUvf0Ry1rA+/xRcGjkULHcGZG1Z33oi7f7Q/UKtmgQxPoNJlNpv7SL6BSyqsWIQaY7E0FVe8RUKf6xhF/u84zUyZcrgV/OgZEAYZkvOvKCGA3zpL8nn0Jvw/rCS22hsQAWipcvsvQtprKQ2ZZnKfy0vI5tXvXS3N33WzZFrROKuzjs2/iHM9ks0xILP6CbdOzdFB4C/Sdjr0CoCgzPtmPNn9dObgCnhn+Y8Gt+8vScDttKtAt+AL2BBdBIa5qpyswmxsQQY3yAuUt4qfpMhSkxdPTPxApHv7SbbWDHFh7+11aif7mQEmj1xj02B6 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)(396003)(346002)(376002)(136003)(39860400002)(230922051799003)(186009)(451199024)(64100799003)(82310400011)(1800799012)(40470700004)(46966006)(36840700001)(83380400001)(47076005)(16526019)(336012)(426003)(26005)(2616005)(107886003)(1076003)(7636003)(82740400003)(36860700001)(5660300002)(4326008)(8676002)(8936002)(15650500001)(7416002)(30864003)(2906002)(478600001)(54906003)(70206006)(70586007)(6916009)(316002)(86362001)(41300700001)(356005)(36756003)(40480700001)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2024 15:26:18.9721 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9e168a9e-45cb-4554-1ee5-08dc233a2394 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: BN1PEPF00004682.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6727 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789710921430176222 X-GMAIL-MSGID: 1789710921430176222 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: * Name labels after the target in ethtool_cmis_fw_update(). * Remove ethtool_cmis_fw_update() export. * Switch between the lines that sets module_fw_flash_in_progress to false and netdev_puts. net/ethtool/Makefile | 2 +- net/ethtool/cmis.h | 7 + net/ethtool/cmis_fw_update.c | 367 +++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 18 ++ 4 files changed, 393 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 06596ae749a5..f8e907a4c7eb 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..a18a7ffb7919 --- /dev/null +++ b/net/ethtool/cmis_fw_update.c @@ -0,0 +1,367 @@ +// 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 cmis_cdb_fw_mng_features_rpl *rpl; + struct ethtool_cmis_cdb_cmd_args args; + 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, 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"); + 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"); + 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, 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"); + + 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, block_size, lpl_len; + int err; + + lpl_len = ethtool_cmis_get_max_payload_size(cdb->read_write_len_ext); + block_size = + lpl_len - sizeof_field(struct cmis_cdb_write_fw_block_lpl_pl, + block_address); + + for (offset = start; offset < image_size; offset += 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; + + ethnl_module_fw_flash_ntf_in_progress(module_fw->dev, + offset - start, + image_size); + + memcpy(pl.fw_block, &module_fw->fw->data[offset], + min(block_size, image_size - offset)); + + ethtool_cmis_cdb_compose_args(&args, + ETHTOOL_CMIS_CDB_CMD_WRITE_FW_BLOCK_LPL, + (u8 *)&pl, + min_t(u32, lpl_len, sizeof(pl)), + fw_mng->max_duration_write, + cdb->read_write_len_ext, 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"); + 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, 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"); + + 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) +{ + 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); +} + +/* 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 cmis_cdb_run_fw_image_pl pl = {0}; + struct ethtool_cmis_cdb_cmd_args args; + 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, 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"); + return err; + } + + return cmis_fw_update_wait_for_module_state(module_fw, args.flags); +} + +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, 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"); + + return err; +} + +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; + + 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); +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 8bbf13cea4c4..bc4ce6393fdb 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 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: 195366 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp234975dyb; Thu, 1 Feb 2024 07:32:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9wj2gjztaABKfNNIKnvc7MiieI1y7EPu4KIQzQBtezB1UqrV4GqxkwWNIZtKL+DxkNWRb X-Received: by 2002:a17:903:280d:b0:1d8:e05d:7a16 with SMTP id kp13-20020a170903280d00b001d8e05d7a16mr2433252plb.56.1706801546529; Thu, 01 Feb 2024 07:32:26 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVM9DNRbazvCMSpJACINQ1w8xK6uArOclXNqr8azqYeWI7sKAgHddp7G3fKlW+oXCpC8ETrjTW36DQgXSlk8/BANqJH7A== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id hi16-20020a17090b30d000b0029023f51f61si3870126pjb.117.2024.02.01.07.32.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:32:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48405-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=ADJJPGqY; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-48405-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48405-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2BB1328D0B9 for ; Thu, 1 Feb 2024 15:29:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCF18160887; Thu, 1 Feb 2024 15:26:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="ADJJPGqY" 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 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: linux-kernel@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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789711138516336819 X-GMAIL-MSGID: 1789711138516336819 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];