From patchwork Mon Jan 22 08:45:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13524929 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2058.outbound.protection.outlook.com [40.107.243.58]) (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 BAD5A364CB; Mon, 22 Jan 2024 08:46:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913172; cv=fail; b=I93Gh9LpZ6KTLzBVcTf1Ol/xwI+WpCVFmJM0aGJ1ZSOBl/suSC9jdUaNzjMZiAXgf3wYMKSGG89oBUYqBl0dFTh3+rTRs4roT1MzsuwhEgDdbUkZAjreVD8tV5IRRsO62b67xyb7HKMbGng4LwRlxKBDzV+lqcPSpqS+LlL23w8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913172; c=relaxed/simple; bh=bMZz9FC0hpSJTWqNuvMPvmiaUjXR7ocPHtgB2At+hAo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jbXvx+Wq/oMXFYi39hc+qphdZdzVOVHZqu/j0eRiYxrfNxpzyN7NpJSzusEEYwzkr4pBA5PNpl4XHWe2S757RUHIHFe8Koz2LB1m2BcspRkC7M5gjSgXsnLHo7C3PmbLCtDWlN3+RyhVVZ2MHhTSPdhOCV+TWVV7fHFF20EZUpU= 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=pE3kdyiw; arc=fail smtp.client-ip=40.107.243.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="pE3kdyiw" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ELI+Oq49qg/M0LALzW/t0/3lp/M+Llc9BlruDCXI0ozvTcXz7AvQFup9KSrZ8AKg//vknAazlr+Tp5B0WI3lf+zFPhx7CTfXD7NwAcSMD0h1zZfg0YWhKZvG6UXvbwVdEYFMcHNBe+wAqHJ8N2uS6NrlfYB01MQqDisaSSLS6jQ2U/tcr60qm92KeiUku1N+siivj40KaFdjTvcnZrM02GpFxXIWwJjNlU4JViIVrC1Q8spCEmzuhbZXl6onzOWcKexMg9HAFfEtJEeQ5VphE27M7pAA3G1Sds6Qxw7ZzXGEUH6bCt9cn9APwqV0fGsVWjthG0EAy8AeVxD2t4YQKQ== 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=Ey2O5ktrthQlwGd9R2arXJH4t+wDrwCX5uMLGaZciKA=; b=jeCC2rVOPZ5r86mwatAL8dWxXqlnOOwaLFLJ5+BzhweDP8aG1sEP+xHUki71NWqTH9L5HrNxUnZxWHBWDmxRHSjcJBFcwXAF7s7YYy9aAc10pgFdVDCczePYkQgMysHqtNCo8aQUKG1gncEmay8NMZ8swrF4pZnGSHxeZuoA0yIUWv/Qy1fAsW31cSlJUFHUBRcMiU7G08MwO48t60xWxO1zNqg4Z8WciUc8Tos3kl5iZXPj66N5dEiYkiWdD/JtnmJoa1k+zGfnUNsDex5EW7Jrx3PrQln2cCeuYxdZkUGjXREJwWeYcrWv8YVLcMmJhF4B+OHUnkgTvsJ2cnQNPA== 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=Ey2O5ktrthQlwGd9R2arXJH4t+wDrwCX5uMLGaZciKA=; b=pE3kdyiwDpZl1mKMBuianDLjxHmWaEnEkSoH0t/hOEqbcfXH4LmBnBdobwTmEiNgbcEeh3tvnPeDznI31qEZdhEhTiiVsyDRa8NP+R9qa0Lc2yYHGPVniwvsGGj6igJDSPkHI0Htv00TrE07DuiiEzby60icmrFPPzgRdurrbY7l9Fq4chy62wtwRbi4D1DzEJhui+tiArWBHp0LBhBtpCG8Wo3QQjWQXG/yI1Iyo0wGe73Hl3Kk88u3EgR63ZrAN1KUVUPI/FtZmkBWlh7jdHfVZ9TwCDIrDTWuyY3v/a9lSKUTeYanC+hXUjnzRCNske4nEMim63V3XLLeZaF+bA== Received: from SJ0PR13CA0144.namprd13.prod.outlook.com (2603:10b6:a03:2c6::29) by SJ0PR12MB5406.namprd12.prod.outlook.com (2603:10b6:a03:3ae::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.32; Mon, 22 Jan 2024 08:46:05 +0000 Received: from SJ5PEPF000001CE.namprd05.prod.outlook.com (2603:10b6:a03:2c6:cafe::2b) by SJ0PR13CA0144.outlook.office365.com (2603:10b6:a03:2c6::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.17 via Frontend Transport; Mon, 22 Jan 2024 08:46:05 +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 SJ5PEPF000001CE.mail.protection.outlook.com (10.167.242.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Mon, 22 Jan 2024 08:46: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; Mon, 22 Jan 2024 00:45:55 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.231.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; Mon, 22 Jan 2024 00:45:49 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH net-next 1/9] ethtool: Add ethtool operation to write to a transceiver module EEPROM Date: Mon, 22 Jan 2024 10:45:22 +0200 Message-ID: <20240122084530.32451-2-danieller@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240122084530.32451-1-danieller@nvidia.com> References: <20240122084530.32451-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001CE:EE_|SJ0PR12MB5406:EE_ X-MS-Office365-Filtering-Correlation-Id: b411a1ee-fc80-4ed4-fbc8-08dc1b269214 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1i5dRMbGY9tqhjmI5gaPbfpfuzHfFsy8JmpGk1uA6Ofi1STZi+jBUEbWkBTh8ADpiMrVuXSIL1MUrqALJqcQqokVZ0/8vMKrGDRL+6a8poEwikPEiHvgVStaRfcBTE5ivIHmkYiWMx2WTIDS5/eOSpr86i2oDdUxz1fajfMX5u9dDJ8rCglInokKYmxx2XUsmR9n+342BFkwC69Kglvqx2RAIDD26kNbK75cyqQOo9wo3KjOMmHrFjKy+Q79LiEF0EbMdba0CF376V+ymuXNE4Zu4R3mwkuN1VMGWL+Wk4uakEuSNpO1MYJxoWx7af/mHla1So/RXt8Ookr29iGhc4EpdJgrkus2l5SogJTy67o1s+YElF745WAGgvhGe1VdYPpmT5wgBpWrat9UGRzu5B3Z1xRnrLO1WniwnkscEKJflQSd4Z0QTg7hNgkIPaehN0lyNZyOLoO1TJCxJXIS1sLKBut9DAals6gWMaJ12SDG40m1rwk9YDijKvIR0a11GXBHUYOiRq/PeQDv018WbDXr017CRbtdzn1fKH6Eve8S3KWgiSrZKn2inlqBcqt2s5TNbjveS4CZuyxBN6U0oUpI9LTDaZr6AePCtbGmcCMt58bj8H4b36VIL4yvjDamY12n9SMJtr/aHlfHhWxtT3x/0DmTMG/oVy/UvNI7Zl35qLkNuspjgQfPKAZny7R3z9fvacnxUh/mov/049o2auH1bM7pBkYJaeU9ke8gjGDumvnyA6C5Y+FD3IA3Y28v 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)(396003)(376002)(39860400002)(136003)(230922051799003)(64100799003)(451199024)(1800799012)(186009)(82310400011)(40470700004)(36840700001)(46966006)(16526019)(40480700001)(40460700003)(336012)(6666004)(426003)(2616005)(1076003)(26005)(107886003)(356005)(82740400003)(7636003)(86362001)(36756003)(83380400001)(36860700001)(5660300002)(7416002)(47076005)(2906002)(41300700001)(8676002)(8936002)(4326008)(70206006)(70586007)(316002)(478600001)(54906003)(6916009);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2024 08:46:05.3011 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b411a1ee-fc80-4ed4-fbc8-08dc1b269214 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: SJ5PEPF000001CE.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5406 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 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 Reviewed-by: Petr Machata --- include/linux/ethtool.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 325e0778e937..bb253d90352b 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -474,17 +474,14 @@ 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: Offset within the specified page, 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 +786,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. + * 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 +920,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 Mon Jan 22 08:45:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13524930 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2065.outbound.protection.outlook.com [40.107.100.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D11839846; Mon, 22 Jan 2024 08:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913175; cv=fail; b=uwBMWdSYLdL0HO7Lxs7bFbyQXijww6eVnOmb31Ucr7yYiIOmOz8l2LcurGtw4WxMYHQAuuk8i72Uv8l8rHzSVyVnYGo4n9yP+mnebKBLEPm90CiK0W+DHztVOiLFbxJqhVA7gpUnJkxIFVOPWmSNbCuuu6FuvOyc2ISaOsfW97g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913175; c=relaxed/simple; bh=2lvEeibgpcsPhkDGLuPvCbJk7df3PcEFc/h04Qs3RSo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sOYecpvXfjBmZGoJyxH9IbqUZVSy4OfH3QjXbPNPD0QuOMV2JbalT6+uoWoPJd9TP9xe2xCbOPqUKcbtrj+5bxS6E5fgWKAW9wa2QLCk5glgql41RCP/B16pmOMs9+EwjN+E883D43Am+LdPnystwVsXDcNCV3Va3td7DfUioqI= 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=U/v3RbBT; arc=fail smtp.client-ip=40.107.100.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="U/v3RbBT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L3ixyE27np2GhRznJB18hAxNBF8wkdpum6OBSti4emluMTZJZKJKk1aXxqu/dalWDGeLX1j69Vkf9co70tHHzh799/G9fv4+kGrB5AJjx4JN7+9/aR1c8j1ruEhSCsF2XkOsT4Ofxfpe9L1FaDO2O/6AKmMjLID9xWib5CgF9kcm+Qwmwy2mbm9davxjpFfFHtc4rHSDqgsmtcAbVRi33ydGYEPj38J547Gg8odF8pa4G/ZaEilnkH9+chbMBsT2uD+PjdYPcnGtpoUm/1fGX95Ggsvw74fjaXZgmF4iGlL2fpBzJQaPVGRQX8YYMPwQfSMczCKoRiw81IQtZ+0t0A== 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=DcvfQSSnH+4J0JigX21NM6c5EIhSO2RCi7FuBNCnepo=; b=RkAA5qFvfhtc9/9g0ZipexIP29butHHkvPEElWdlbsUeZpEvoKrq20YidnKBhFCDnIaHXn/prJ93boZYMvpC+9ZQ/AFO62QNiogxKDXZwVdAwoDkbko4LCAu6Sp2lzZvcz8Whcmum4QCIXPCwjbzhNCsu7PFhFIxr5cNq6godKcjd1CwdIjwh+4/m1mGRC6crqSj343jNzIX03XF+vpbNkL3T3Ak8RoCzCHS57yIMkynWLlYrq/44l1nGM97vyT563WAYbRx0q+gBH/rbEhwkF8fm78uhjbIfku4PIToWN/+iEzJDd3wifNizmaJCeg5lI3CMPrYZA5ZLfKcLGYyhg== 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=DcvfQSSnH+4J0JigX21NM6c5EIhSO2RCi7FuBNCnepo=; b=U/v3RbBTuqXIbiH6uQMFKxriMFAstN66ApcZfyG6elW+ggTyKDuIjr0BjRUdGBwzNXcJA6Khr4sDYER9+q+pYtHzCZkU5E6ct6xxkVLrIAE/5o27ug8U2I6RVWR7vmC+UFmfnmwM3RiWSa4jH8mN+T8R5AuRSInE+IRF6XPVxsocsWefmmaWe6EM6XHxyOqAeTxERHQ/riIto0IvPEbedhVKOQcY2kHEQH5D4mZTAEffAwKmno+mc7q5LQz9nC7XopTEonE1Q2VMspb6PqlX5FSigH3DJOgdw4VB945HHi/SNY8llmFViDJpP/hfnmRR9FgB22cvjBYkJGkbclK+8w== Received: from SJ0PR03CA0012.namprd03.prod.outlook.com (2603:10b6:a03:33a::17) by IA0PR12MB8929.namprd12.prod.outlook.com (2603:10b6:208:484::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.32; Mon, 22 Jan 2024 08:46:10 +0000 Received: from SJ5PEPF000001CD.namprd05.prod.outlook.com (2603:10b6:a03:33a:cafe::f0) by SJ0PR03CA0012.outlook.office365.com (2603:10b6:a03:33a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.34 via Frontend Transport; Mon, 22 Jan 2024 08:46: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 SJ5PEPF000001CD.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Mon, 22 Jan 2024 08:46: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; Mon, 22 Jan 2024 00:46:00 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.231.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; Mon, 22 Jan 2024 00:45:55 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH net-next 2/9] mlxsw: Implement ethtool operation to write to a transceiver module EEPROM Date: Mon, 22 Jan 2024 10:45:23 +0200 Message-ID: <20240122084530.32451-3-danieller@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240122084530.32451-1-danieller@nvidia.com> References: <20240122084530.32451-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001CD:EE_|IA0PR12MB8929:EE_ X-MS-Office365-Filtering-Correlation-Id: d71a7a9b-7e2b-4657-bfef-08dc1b26951f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Gs6JeXDb+D1Wkc99a0s/6Nh/+Ajf5NHn6y2gbvvOHzj3OvC+AWY5IzGCsSxR2vkMwlNYYOwiruNTFfGU4cAmemle3tPucVGBiEXavnp4RhgzBjm5TNBnUxJjyAFP8UJYPDkHEEKYqzBiGf+vNJJGrjD4F69pNOmBV+yYdBwZRg4LRsYsblnrDSYcWOorix1yVzODTd/mHh2AOuiRVyeWWvvK4e/LFaoFGe3JNLbrPK2WezohzxET3ADt6QNhM0gG98DCVSf/eeBWVY2bdlJPMBoh09DiCB7w3zdtwJUhiqgjxz7PhZ7I5eP886V/kBMuAhoBmyi9sAHulOweVdUrvaMsYgNPNdhmJRxD47dH/RdTxY+gB61sIAtlFEFnTHjPODWgkOJleQq5CjSoD5vkzhEOzoE5UnyqZIjh6Bt7gqsxVu+gm8wmCShAcQw7/aAQiIzev/C1X72OESJOJSvICFEltacwNBgO1xaRgLQ6A9xslaKsWx+iKLSpe1hgANzJjg1FVLw1JNOqMEwfg8DbS3SLMNdQ0JoOMdpTAjXd2SjfJb97FMvrmtGp707YXaUNTlKJXBHUmxXBlYwWBZm3wPYEbc2DphifxBWD8B+RDvyXOm31DfLQjmUnbsI4ulzeyPZBcQCPEJ2Go1xjkJNXiEpDy+CcA5THJtJGHyvlwjc2haHsRG9ZOmmBfrrnGslyLESte2qbUT6GwwKLXJY0lX0bh9swId23M7OeBMpCxn8= 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)(39860400002)(136003)(396003)(346002)(230922051799003)(1800799012)(82310400011)(451199024)(64100799003)(186009)(46966006)(40470700004)(36840700001)(356005)(7636003)(82740400003)(36756003)(40460700003)(40480700001)(86362001)(83380400001)(426003)(16526019)(336012)(26005)(107886003)(1076003)(2616005)(36860700001)(316002)(70586007)(70206006)(8936002)(8676002)(6666004)(54906003)(478600001)(6916009)(47076005)(2906002)(5660300002)(41300700001)(4326008)(7416002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2024 08:46:10.3892 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d71a7a9b-7e2b-4657-bfef-08dc1b26951f 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: SJ5PEPF000001CD.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8929 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 6b98c3287b49..e52be38b5495 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 Mon Jan 22 08:45:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13524931 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2071.outbound.protection.outlook.com [40.107.212.71]) (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 255EB39AEC; Mon, 22 Jan 2024 08:46:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913181; cv=fail; b=pWxShX+8KUz4Y1TwlD/PMyW6SEIihjlTgDEYtHy31zUeV+pByHDxr6Dj7wnO02FzZyhoNL9/I0CZ1QowBZFN4bW+paiesF9wsicYbFtGEiuddIhvm2oiVvrMPUHFFqSOzN1OWs74MUDISZ8rxP8w4iswY82t775dElkHO/wsfic= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913181; c=relaxed/simple; bh=k409HkCzY8OXEZNFzOL0oebBYNn+19HmfRnNuJb+iSo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hdyOEpZAiKYjADA7R+vyfHatQ2fk/RcAtHb66tkCDl0zE1qRJ0JM2e5lxfi33Iet8teLQ5OmK3JuXEBHxyKJSX/oqZGawRLEj2ycr2qYb9YZWU3QgryUisPXSw0CA8vL2UsKaeavuihaMOd4Ns1s5FOq5Au1PPcTjdUB2cT/xls= 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=WoaDbTd0; arc=fail smtp.client-ip=40.107.212.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="WoaDbTd0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cRK3vBW9vQRWMzO/UvxadjE5mnGghwVeRGI15VbrN01FEAbJZy+cVKRMdxf3t9EivkzSDiHoCuyrELY4oN2G+Rg8ro7QDAc6X/rtIGciD+00R6wS54Bt3OCCW/H3OqxYzOjJQzlwKpx530Qw1/utC4uEhc/Kl3HxMZay9SjQRj2NxeOTYrHPW6rW/EtKTwUmU6+H9dyxBQDYTzy4uQIQcHPd13/aWBi2eOSHSavRkQ9/Tjgb36Zf05DFi6g6NCNfZ2CbV9xMr2xbyG5yKlM38KhUDoZydbqFV6TZ9IaIt/lBbbp5qPD/oflOQVyD0GQkz1VehMFQZ299Zs5MYHBwEA== 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=ZV1d+qMLShqo8omCqrDxFnEhGVIbXvb7dvrjw2ZkKw8=; b=JMnWA/Gn7l/Ssy9zMB2G13v7+UYNi7mp4piY0rKzkosuuTvAfQemxzXSavcvtZPBHd1dvxS4hqX0llkKlqsyT0Zhuzdv4+XlfXqU9c529LrVomc39QrW7U7dMN+mWsK78VS8GBCP+m8PLf0wX8gUEij9yuGeeByCkwnO3r8t0G9/N5TvvZqEZUZ/EwC318Byi/6E0tbX7SnwSC47G0C3BeUYMbVs0vrf32oPZ0bFIuhqYYJj7mQkSIC61n1jnxyHek+NtQ5IPooU9dLgRwBw2IyMOoTXvfeagCq8o2cPFTd3eSvEE9czh4NQio6AJNYKo5XGd2ceMxRruccPoh2lMw== 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=ZV1d+qMLShqo8omCqrDxFnEhGVIbXvb7dvrjw2ZkKw8=; b=WoaDbTd00pEL5HVpBAiQXutH2tl8Asr+yZewo+rZCLTw5s2o9HdHTExpxsNnr4m1Gh/zXEJOOClBWuMtmjGcF71mC6lAuBm3CQLa1LtArKsE9Bpr3CkBG6NK592+xyxr8PeKF3G2Y6giM93pla4hPZiICugYqL0NJ8cz3r/2f6MuFMJ10QY/+K5zEeHFkDP+z/95QENfw+KODY6DefDeUfRDNaHc8hZJY9NRhkyT9KjGf9vn2LoU8FnMMhHUEZjQEFgGMyr/k6DD3HB5qluzGesFahcSi0n0qg+LnmxnBdvyvlEKEX4UI0+3n4Rz57Z3yI5+O1A/xob/7013hnDFbg== Received: from SJ0PR03CA0019.namprd03.prod.outlook.com (2603:10b6:a03:33a::24) by SJ0PR12MB8138.namprd12.prod.outlook.com (2603:10b6:a03:4e0::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.32; Mon, 22 Jan 2024 08:46:16 +0000 Received: from SJ5PEPF000001CD.namprd05.prod.outlook.com (2603:10b6:a03:33a:cafe::d2) by SJ0PR03CA0019.outlook.office365.com (2603:10b6:a03:33a::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.32 via Frontend Transport; Mon, 22 Jan 2024 08:46:16 +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 SJ5PEPF000001CD.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Mon, 22 Jan 2024 08:46:16 +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; Mon, 22 Jan 2024 00:46:06 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.231.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; Mon, 22 Jan 2024 00:46:00 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next 3/9] ethtool: Add an interface for flashing transceiver modules' firmware Date: Mon, 22 Jan 2024 10:45:24 +0200 Message-ID: <20240122084530.32451-4-danieller@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240122084530.32451-1-danieller@nvidia.com> References: <20240122084530.32451-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001CD:EE_|SJ0PR12MB8138:EE_ X-MS-Office365-Filtering-Correlation-Id: 164214de-310c-496d-0d3a-08dc1b2698b8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WA/4W0Wd/JJ6b5TjNC4b0bUVJfmpqe0PTyqP1ApZii7uLTYLcbqwlO1EL0SMIcpYcaPRP81CqM4Qr2nZPMk/L5qlRZ6rZjJ/XNr7ydFa9labaXjlh6UXFHSikfhT23Zm2SLrtmMlvOS+yoQpdr+QrjyHU5XyIJX4Hrpk2q59c5hFp6+JFKfS2cWIvWUnaTRT+BnS+eg2pfXCdp2aFLj6redMe2/Tl5LhcFqXWwTL0TzT8B/+r+W6ZqmLyAXSdnSKZBT27L0oi6D8ZpzSigKxaz/RkLXt3TfKl+psnIhNAszaIYHMdqJv+isx49Dun3QAxtDWHbgU8z+9ScJ6nSAWBEl4/7zAfpcrBR3Ldk9VAOytIo2wrr3BsKDcZiWZbR2wpODCI5ZV7XLw0IyI0aqGHkKwHGSLXHZPYYl8ynoXG+adgwFxj+xjdIOgsm7ngLBSDkXmd96ChJ2P81MNEspmTgle8zw42XKbfA64SXXpcWTZ3o/FQkfxpiqU19lRPIbpvzBf12edguFNUhfMCTgJkMzXx1hkM5aTv3IowBk3hUWGD7O2jQ4UVMVTt/23PnsXlcab3SlV0ygv54zdMCYkhM7U2XmbfpsGlD4ExfY3vUtqSXFakwr98z0uAxg/QcemlTsC2RLuVxA6gRBSXZUpVjb6nOT0+wWA1lW8Iv2kYMp0jko7rDSruhfXEqrv1ci2KoROyPiQLyNq80LHT8ztNNbF/wP1jTkHJ0C/ivP+dxCDrHIbJ8j333EAP4RLPfUQSwNdkphZoTsbgWRdFi4BYg== 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)(136003)(346002)(39860400002)(230922051799003)(64100799003)(451199024)(82310400011)(1800799012)(186009)(46966006)(36840700001)(40470700004)(36860700001)(47076005)(36756003)(41300700001)(86362001)(82740400003)(83380400001)(7636003)(356005)(478600001)(6666004)(4326008)(8936002)(8676002)(316002)(6916009)(54906003)(70206006)(70586007)(16526019)(2906002)(5660300002)(26005)(7416002)(1076003)(2616005)(107886003)(426003)(336012)(40480700001)(40460700003)(134885004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2024 08:46:16.4205 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 164214de-310c-496d-0d3a-08dc1b2698b8 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: SJ5PEPF000001CD.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB8138 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 --- Documentation/netlink/specs/ethtool.yaml | 57 ++++++++++++++++++ Documentation/networking/ethtool-netlink.rst | 62 ++++++++++++++++++++ include/uapi/linux/ethtool.h | 18 ++++++ include/uapi/linux/ethtool_netlink.h | 20 +++++++ 4 files changed, 157 insertions(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index 197208f419dc..73adb23acccb 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -942,6 +942,38 @@ 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: u8 + - + name: status-msg + type: string + - + name: done + type: u64 + - + name: total + type: u64 operations: enum-model: directional @@ -1693,3 +1725,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..cef0c51dd21f 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`` | u8 | 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 Mon Jan 22 08:45:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13524932 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2079.outbound.protection.outlook.com [40.107.237.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 CA3EC37168; Mon, 22 Jan 2024 08:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913191; cv=fail; b=DVgwOmWmi/2i/Ui7a0L+6r1/3HFyw7OwvCV9LbwIdhss14vk6wtKj6HWEEUA2aZuQZBC/bjFewG9f8FMNPoCFwTm5oabRPS11MwTgAS1pPxzx08hB0vk2Mv5ygtIAm2SE9V1fpdL0PHvdSTEMpma/vr66F50Y9UoI/mMj45a9VY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913191; c=relaxed/simple; bh=EAkfmtUOBzV0QVAoEUuRt2lt623wUvAoV+i80jPNMCA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CNYuuA8UHWtgQXi621Nlt69/XwGgEHyXxFsiqxCs7gXuQa9E3xGPnU9LA47wP61EH0BAQn7DPaZhYyKsJDMOEgeGZTL6tC2IvCUBViTWikZgzPH1PalaQrv5Y5ssh8FafFWB2P4/ya31VZ303M9RSc/ydzhELeLjPScMyzzVHHI= 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=c3jFBZaF; arc=fail smtp.client-ip=40.107.237.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="c3jFBZaF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RcAHIMjr2YUU1n3J+aFEoAIHJ3eThfnD0DFS78pSC9yl1jQPFpG6f8lgdRYl6ecbfg1BF4f6OaoWvgxxiReuG/hWi8FSgdyIOrPeiXIiT1HGkvgyh0La5G8mIQeRagYC4AuxdVriXPqsZuBj/p5JNEr1LG6QkKh3is1/Z5rmeRa95MZBJwRG68L8mQ/UgrzkHhYVKVxnd1e0yIQ2t/JPCm9dJM1nfikNeGYRYvJwnUtv1u2TSNuGsrP2DhxrnuFEeXEuue2SLgJMolkcMOk6nwpckeX+uqVHoZm06Y5HRkQP0l8PXcFDKhmbGMdCvXzk0et6kYSFeb9M1hqCl+IhVA== 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=qNFL1/pk7STUDTmFiWqOmm0U+rpuF31f/Gt61/+3l00=; b=GEXG8QNHs3zhm8mU5y/T7DmWb8yyVndytluV2d+z5yEWmvOu55V6z0AiwUU4yI/sg4ywvXYnEOJjgT6c2BTBEWAJdlpoumQ0ahqcFSZQm2VqRgRBcieT3jmVkPUT1UAL0/bYvRDXxLNwTdy4vz2dHhnpGt/wSYBp5EB9eoK0exNKjsxxsTeEANKch4IajfARnN9XXP63DIBiDZ8RztRC+ajlW5Z+lgOZ4YsUHtNf0YCySlG1i499/noU5v/lVAZ4cxR4SilZTBp2wM53IRCH1EHRvFl2/BPp7guLlCBc2CToan0lNCfnJzNs+SeV15mMqOlbGp0XSG1FzgO2EjIJpQ== 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=qNFL1/pk7STUDTmFiWqOmm0U+rpuF31f/Gt61/+3l00=; b=c3jFBZaFiuBGFKfbsTlDMm/ZvwvJCHz8miWepl3JRfMZqErCAekkwfqBjOk0Ks3Ji0VDy0ouxH886VHw5KSKv+UFMuVKNJbmXccU2cbVQn2tNj4uQolCD2wF5H0k6KppTR1MIWuxKs7VwGDtd+IYYPjOXi05pLuDbx1ur6+iufqgr+Wcr4hJiNXDl/thjvNMRxj0Nk+ORr3tOuGRQ0MUvN37JNfmVuTY6CMm/ESUb1Ds/XLt2n7O+KlOfjqq8Y8cMthVywoI0Bd4WquyDY4Tlkn/F7CTzEm6yQYIDFynLY00SSF+2Kni2/+fZVKPf9zhtm3ckvsVa9wdm+F5AVmwrQ== Received: from MW4P221CA0002.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::7) by PH7PR12MB8826.namprd12.prod.outlook.com (2603:10b6:510:26a::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.32; Mon, 22 Jan 2024 08:46:27 +0000 Received: from MWH0EPF000989E8.namprd02.prod.outlook.com (2603:10b6:303:8b:cafe::5b) by MW4P221CA0002.outlook.office365.com (2603:10b6:303:8b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.36 via Frontend Transport; Mon, 22 Jan 2024 08:46:27 +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 MWH0EPF000989E8.mail.protection.outlook.com (10.167.241.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Mon, 22 Jan 2024 08:46: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; Mon, 22 Jan 2024 00:46:12 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.231.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; Mon, 22 Jan 2024 00:46:06 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next 4/9] ethtool: Add flashing transceiver modules' firmware notifications ability Date: Mon, 22 Jan 2024 10:45:25 +0200 Message-ID: <20240122084530.32451-5-danieller@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240122084530.32451-1-danieller@nvidia.com> References: <20240122084530.32451-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E8:EE_|PH7PR12MB8826:EE_ X-MS-Office365-Filtering-Correlation-Id: e43b5906-ff02-474e-e023-08dc1b269f0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vtsmDP7a3Ioe4shdZ0rJqK3Xkl0pLI86bMyYk/p7i4YgV2hfKaOZWRObND0/Jrp//OJkT5txO5RO3GhSFSqXQwtrXPaYICHTc74wnZVn9zyoPOzEB71/ai7Q6RuNONJPushCdFee+sOVlCHDWzdqZKZuA2Mk2qowfYA78kn3vMhbf5tpapXA9YNjT70djIz5zFEXFwWvmhWZxtYPfkdl6hHal6aoJ5gYcWivDTla1VOCBuIQw9x92n3GJ3gv+Hf2V1CD9zo8378lQHwNcz+4M8H9d8BKC75Yb3dBKXNLmOPWQLtECiyV2E0sXEWQSeOKOSlq9h0WAATkr9dqrQ4iSc0ZQgCOQVtl4oQsCNKwmVBBnIPDbNqX0gKCq72Dy3X2s0dFMgPHUxLfGteFNuMtVpBlG+hiI7CsbqlxnRN83CEIUAomjKZ9dqBCmSIGRQHVP3X6vYLQFjX93Y9IXnIDS0oVHzbxxc3i5vCiXMuwKlLxyNQOl4LE8EewVVdxddaoXUYzxAM1u5HgFox3bsXpEVgVCgYNEWr6VQjDcu5FrMQrCPtpKa0PJ8v9WklY7d9i2iQWNo6wOJ1k0DEsmHnC+nopKcwbtRTBhM6Qy11FNxBP/8YVQ9g6tbx7bHJu6cqvE3wgxM9FOFZbvgQ5zEgohGUzV/9Djch742FBP4oA+gN7RzAv1cu8CzOOGK5S2TyFvqSoG8r+wxy3VfwGDeOS65TqQQ/ws9/DphiviW8xATOo+mCwmCxmJHmEo+bmO9eB 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)(39860400002)(346002)(136003)(376002)(230922051799003)(82310400011)(186009)(64100799003)(451199024)(1800799012)(46966006)(36840700001)(40470700004)(40460700003)(40480700001)(426003)(15650500001)(5660300002)(16526019)(54906003)(70206006)(7416002)(70586007)(2906002)(26005)(6916009)(478600001)(316002)(6666004)(4326008)(8676002)(8936002)(2616005)(1076003)(107886003)(36860700001)(336012)(82740400003)(356005)(7636003)(83380400001)(47076005)(41300700001)(36756003)(86362001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2024 08:46:26.9530 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e43b5906-ff02-474e-e023-08dc1b269f0f 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: MWH0EPF000989E8.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8826 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 Mon Jan 22 08:45:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13524933 X-Patchwork-Delegate: kuba@kernel.org 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 8AEF9383B2; Mon, 22 Jan 2024 08:46:31 +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=1705913193; cv=fail; b=O+t5x0oyJ3ceR7QJbOPu2Ci3jupV21sMJXNiUDFpNXKHZ5b/q/+PQT23N8PClRr8nfJUPAFpc7YdAN1KoHhX18UuwBu3fV4Gjx48O4Th6QprmMr9cYPH6TBSAx82bL8AvHBwr75D9qUCixH+EZxmusOIL6pW3se7yWBYLt+hdMw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913193; c=relaxed/simple; bh=befG10zAJisEI2oqZKTRP6IogoAhrWj0v9++9UzuBM8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oYMhA6k2wdkXHXgc6yw7skDzWWlTTTa+7Hter2DZ0z12jHiLSUjNleF+zyiEeBpoFR+sqBbzcj3PSrEmhkEJQrUQlt68Odx15Y91NhFu0g7C+QmZIdfUE1uPXPk7EPHwdS2IND4m9va6FOi011X4YMYojOxTGhGyqUkVSvkePyE= 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=uoREH7k3; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="uoREH7k3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jry4qKnuzh5BMMg/e3HyAt1Nqrj1o7gu3Yg08GMj+2R022hcWjk3LIMhhFlsmLY2Y+VWVFgK5gwUO/iloiePiElgdAdWt+NFLTh6n3dXz62iIIwm/M3ZYfeQGgiYCVz7A+4qwf6W9poLxHWI+2VZyD2uYsOb4CTm5Lmer/0GHw5KEoN6Pp3I5tswBJSBMr7LWEAJIV1iKZ2Dq/wUFXXfZXsnTTu6PzTSOq+S16hjWT/EbAZLIWNT7se9f3hfiWFLWHBwK7ghQyqxaJYSlEKkmM8qdG7ThqHgqdw0vHjqDLms8q0n+/Cy+/3260QRe01n3KJVn5tFtk2wJWZ8SGKHyg== 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=IKcWA3CsWvDr8aJryflbVSJ+UKItcmsrl24ATk1Bn1M=; b=EdWlXzNXM2nYhTeHMP8E0m3oMqMAr8tW0ouuEphjRf3hd+NO3lwE9uJv0C0igmtvlGEWteyqHU8lvBX8AfZTuSpHkPrkN9Wrn/CxsJFtfysaxyRgkU0/QKJ6t3Kl4BUVo2cHEf92Oy6Rwz+yhaq5g/PKmzgHJbIG+df00WEUwDln45bbB8qsetO95PP6/IwFEg6pKLdKMGsRWdlO0vE8xaXt4Wrf3rVjvMZg4v2n96VnugaFuuHf9YuLduHdduYDhuKIA+L1bw0NCdxIMgGwQpiCoAgyHnHWZYvYvnX6T1no5klmoV/32Q05kiaK5mngnTMpvlrm08ts5sJ+mbsn5w== 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=IKcWA3CsWvDr8aJryflbVSJ+UKItcmsrl24ATk1Bn1M=; b=uoREH7k39bcQ1v4uENXgvZrcJcF+PiIjzcPMG7UeKgvu9NoCR4rVK5sdbZGppR5q8TcG9vI2WxRVrM6MmUhu/DeeOhSTIK2MMOJfDM1O5Mtv3HHyqpNRtQnNiHXuyval8EV8AQj8GgF7kIhLcy9OElSDpiNnp9aqOkMTmhzujSpKBQ8Mnchx9c1/rNSZ6B2PGGFw62RqzHxjHy13/DLX4zHdc1e7UZdtiUNDhKWmy+aOKutdINHejk7cwoIT92i5qE4y03vR025IXFwkLVr65Chs4HGvxjGYLq7iv5OSto5kvVyGbAJFsaNHf4qQnHQO/z2jlxia5lWE8hah3+GDNA== Received: from SJ0PR13CA0147.namprd13.prod.outlook.com (2603:10b6:a03:2c6::32) by CYYPR12MB8855.namprd12.prod.outlook.com (2603:10b6:930:bb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.34; Mon, 22 Jan 2024 08:46:29 +0000 Received: from SJ5PEPF000001CE.namprd05.prod.outlook.com (2603:10b6:a03:2c6:cafe::15) by SJ0PR13CA0147.outlook.office365.com (2603:10b6:a03:2c6::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.19 via Frontend Transport; Mon, 22 Jan 2024 08:46:28 +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 SJ5PEPF000001CE.mail.protection.outlook.com (10.167.242.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Mon, 22 Jan 2024 08:46:28 +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; Mon, 22 Jan 2024 00:46:18 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.231.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; Mon, 22 Jan 2024 00:46:12 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next 5/9] include: netdevice: Add module firmware flashing in progress flag to net_device Date: Mon, 22 Jan 2024 10:45:26 +0200 Message-ID: <20240122084530.32451-6-danieller@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240122084530.32451-1-danieller@nvidia.com> References: <20240122084530.32451-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001CE:EE_|CYYPR12MB8855:EE_ X-MS-Office365-Filtering-Correlation-Id: 31847263-1f48-47fe-f0c3-08dc1b26a01d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uRlPuDvZevb/oa9LgVsCfESEYIyzuJmRaCXmvJALNgvC3ei6cDk2sE+5Ws97N8JPhn94bQOttqQBlIHJMcozoyZEbc4a0ImX+myUvZ9XznHFgs5edC/s+MxNK1Qu96xGjmHe9uFGETDf+zkt/33n8V8LpfSKAD0RCM6GryPB+sdGsvAvo1aTVvVRnjJeCDgM1tI8LxbU2JEdxl21e8wazlobcwO5XhzWwubvfEQ2cIphSOdvgp4Cd/wonptKC/Jj34G+KnIoTSuAZEbLYmKcM358ZNhAHGpTM1PjpVOSYNztg1uFCFQWgI411p8dze2jn+VZpAfZzOysZKAwQR+oTBstU1+Wv5R46zcuYltwAIJ8xHSk3aPK8+5EdSTka5UXIcbLNgKJagbWL9M94SVaebSS+bu6LeiZ0m6R20R4Iz9ZVrROnpgC9f8e9+VZabNT2qEDlrsbfvOhmiBRCGs/7Q2bIDIBu3bqXpy3R/xwEctQ2g1/eFfMwNittuh7qlJ3QfKVPQIKYFkpgekEQFjdMVCDG44Bpbd0QnZXH+j282xhCj/k7OrlIApbYRIIXhlTfLFEHWApr33VHRL/E8hhObW01zU9rqcGHDJL6fs5hOgYBlqwqWKo6h168jal5QcD8s+0ZjVH9oZ6vQS7dQ/aRLQstWM2iNlEVUQoAkCv7HiFrREC0t6vdf9LowrP91QZnOSYoONv8102Qbj/O8y4zreUtxE2XpkOcDHc4LuTyi7WF1FR3MeZL59dtsmE6LcD 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)(396003)(39860400002)(136003)(376002)(230922051799003)(64100799003)(451199024)(82310400011)(1800799012)(186009)(36840700001)(40470700004)(46966006)(70206006)(316002)(6916009)(70586007)(54906003)(40480700001)(40460700003)(6666004)(2906002)(47076005)(5660300002)(7416002)(8936002)(8676002)(7636003)(356005)(426003)(1076003)(2616005)(36860700001)(336012)(26005)(83380400001)(82740400003)(4326008)(478600001)(16526019)(36756003)(107886003)(86362001)(41300700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2024 08:46:28.8479 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31847263-1f48-47fe-f0c3-08dc1b26a01d 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: SJ5PEPF000001CE.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8855 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 118c40258d07..af42125ead69 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 Mon Jan 22 08:45:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13524934 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2060.outbound.protection.outlook.com [40.107.93.60]) (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 5CD6F3A1C1; Mon, 22 Jan 2024 08:46:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913196; cv=fail; b=lj49hLEV/yOwLUp5seeDPfR7ghC1w0OHZ8cnE3T6lRsaqz7M4gH9LGAxKeviKmtIMEh2Vx60TRwJWsuAGKpBdaRSgDF+eIH6uXltyIzimmCCuCSUV81LQorNqBMXQg0aRc9CNwzdAXOEFSctXPHUpoc3n/KpjZL/DBl9uqrXbRA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913196; c=relaxed/simple; bh=zhuE1rZicWX2AXzR15Z31led0L/WimQNyXp5JoRx5U4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iU36z66+AA/TkE7lfR0xcwXomIU9op/DW/DmHp/0y8jYR+tEf/Q+PdgDKZSNa12zCSFDVMpU5+MZrKaluoRS2OPaazX5RRXj3sj18P0PEZ/Lw6u59DjLoc7R9PeUaFWDaONfLChv+zAO2+D59nRHMJuRgATPa4INEP1VmIwZRKo= 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=ppZgUnQu; arc=fail smtp.client-ip=40.107.93.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="ppZgUnQu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=absauFqjdcJoN45c/l7hcfcq5pi+YMRRaKlH6Db6g2SVQfv8764BzJdN6B/vLiKB2+jm7tO2R9uzklLTu0SNdCnXTG7Me/zS4w+6x2tFEkt/m3iGkWF9MMtqXcF3ic1t//eOAv93GAVcHDUtfeES5WYOHawGT6x5rHLRChjjh686vxlSpvihqp92LDPisAm8SF6Ena35FaJIKOptzQ5WrjN8pt6Tp3mG+wSiOx4UvtScpMRpHH+T7x9cOn484WENmrqC7NazReU3hkYlWU/NvY/yJuJFAJEAg2gD/gXnwXGAovNZiK2TsIg3iDaC7sY66Hf7OVkK73Th2ssH/MlFoA== 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=+QZQV4QjYbmSpID7F0sWWbLxTIFxC9ENB+fQ0lsSgbc=; b=cl15WE+8QpjgOn0x+C9Z9d1KB4aHvB4cw52Uk2qWP3eZyrujiZ+TbOB7VP5SQfiWxaSPJtHEqSSI7/IgSrQzshXniOKcZv0iilYlgahBrm5if3CwtwatzdgbIu7PmWqEx0OCtIKXBlOfx4hDyldUyZ/vlrgBZtBhLRErP75fxlcsIA/n58x0tlcbTeVDTjn3uTAC7TIFyNTKxVSdovxOSi2fkrISApKAYdgRSSfP7GFG78lZhQPsnPj//6qpd45tg1FGD7pjscy6dDonWYxk13LXVD1dOEXwnHb2zTCqydytXTGXfK1uZQ37unNy4a7bQVzCZtdtrbHL/Iu+/XD81g== 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=+QZQV4QjYbmSpID7F0sWWbLxTIFxC9ENB+fQ0lsSgbc=; b=ppZgUnQu2Z0Yg9L6baS5DNJOXN6AQWwjtz8n3QejpZHJ6uehblXVlMWC7Vpa4cohvunp5H+TuCW9HTmZoMq30uSTWAB3uYU5/7mMLazw6XzMtqsd+gfYMBs7ds66yFkCS6PkhYLzXQ2q21GsHR/Ld552gq3GJWvwGVof2O4a4c1sQpR8NW5vwfQBc3L+pckMuki3fluvFHY032wX6wM06GyI2G+u44RDXpIeLA9cuospW6Dcw/HsU1CUxDOYELPCKWok3433WZgHOLjNov5dYNByKs3tSLmRvv5zEQyHJFWPI98DKZ35SSswW/IHG99U2LMn6K+WvgRCHNQkUCvPDw== Received: from CH0PR04CA0023.namprd04.prod.outlook.com (2603:10b6:610:76::28) by MN0PR12MB6272.namprd12.prod.outlook.com (2603:10b6:208:3c0::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.32; Mon, 22 Jan 2024 08:46:32 +0000 Received: from DS3PEPF000099DD.namprd04.prod.outlook.com (2603:10b6:610:76:cafe::3e) by CH0PR04CA0023.outlook.office365.com (2603:10b6:610:76::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.31 via Frontend Transport; Mon, 22 Jan 2024 08:46:32 +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 DS3PEPF000099DD.mail.protection.outlook.com (10.167.17.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Mon, 22 Jan 2024 08:46:32 +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; Mon, 22 Jan 2024 00:46:24 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.231.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; Mon, 22 Jan 2024 00:46:18 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next 6/9] net: sfp: Add more extended compliance codes Date: Mon, 22 Jan 2024 10:45:27 +0200 Message-ID: <20240122084530.32451-7-danieller@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240122084530.32451-1-danieller@nvidia.com> References: <20240122084530.32451-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DD:EE_|MN0PR12MB6272:EE_ X-MS-Office365-Filtering-Correlation-Id: 445b04fb-4124-4ee6-8246-08dc1b26a263 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wSOs/wH9MZgnOvMN9AXsj1npAgG+zTaMuNsrD5s5eD3ejbf3XyFNUKR/rdQNpViT6j0pDI+uGjBml/xZgqBczTth24cFf/GzCMTgrlmy8LrAo8iefmD6CuuAY/pvvLryL5g9QEPy97EAZvNgTAR76v6tzzyG8t0a3Dm0upwpWoV9DheZ/Dfy6cEAx7P8JLUWLPYGeB8UXC8a1Cx9BofGsYWJv6zgjrxCe/mJoWcL6pPOWnh5attAPgkJOhFQT+CQl5GgKApbtKDDU8HzxYB6UDDECl/ys9xKa1CHGE8MMUJLkvTizb7HSbtdFXVUl1GQeNzVS8RiuPzxHZ1+co3cZxSbr4ewRNSaqhwZWUiEQH6+LlmRGyS6qMyT9YH1dQRvfC0NjVuMKSVumaxAbzRLqIDLDPKfrKbMQ3xle3q9X5PWuI4uO2/+if+yjFfzU+uAqN8lQgZA5D8UdQd9pDEtejomLbHFmHt6PsBy1gqdD5ASWTzvskEyiKN0Kuk7aYkszegsPhxABDimcqwZFQlJZU4nuA8h2RsUV8zkRxHoM3fbscBrc2pJb8/sRsURgnK3zRKmcT5Fms5DRPr0UcgSwZUx/zdoBYGo61QBXA2EEbQE3Ld4A0/vd6g62QafKUtYIkg5XMw5WTjxEun9WoiTs8YOZGFl7XMDAUcMnccLI2/pyWP7rl/pwdLNkAQGL5rMWfjvgBeKV6j+Z9Yc3HNuK5rLrFIS8KgAYADufMiQOPGjlaYZT3I40cI0TWu6BYZZ 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)(396003)(346002)(39860400002)(376002)(136003)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(82310400011)(40470700004)(46966006)(36840700001)(40480700001)(40460700003)(47076005)(41300700001)(86362001)(36756003)(356005)(7636003)(82740400003)(36860700001)(336012)(426003)(107886003)(2616005)(26005)(16526019)(478600001)(2906002)(316002)(54906003)(70206006)(70586007)(6916009)(6666004)(4744005)(1076003)(4326008)(5660300002)(8676002)(7416002)(8936002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2024 08:46:32.5499 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 445b04fb-4124-4ee6-8246-08dc1b26a263 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: DS3PEPF000099DD.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6272 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 Mon Jan 22 08:45:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13524935 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2045.outbound.protection.outlook.com [40.107.243.45]) (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 C8E0E3985F; Mon, 22 Jan 2024 08:46:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913209; cv=fail; b=HIQpz0G7r/NA9fsgb0GfMIlPQaQmT1eD5NQKmSIvYH9zWuTmpb/gfNIN/qCmllBsGH5PWKKxkFFz8ym7uUbpqYMniz2G4fD6jmzkHW1e1+SmbUWGa2FCBKDbkiUfJhkvm2bMszO4hIPvQY1etaSMIiljdG/z7Rz73S/YlnOrkmI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913209; c=relaxed/simple; bh=JX4vfr7XrX7aXfmcIwhwaLHIpqHfLLc2YY4Z98q6DKg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mXfnLoW0u6dQa6SpWRJXg/pcirzoy+1q1rvgHhdyol9xaLHe2Ms8bAwQziY80LRxMakYcNr81ZuJ/FN5kAe6bOOUU69nKYceQDFlgmdi3BBob9nho1rSnIAapsmIUOoOmmTysx0hqpven2RGQzVI2zlspOyiuAmIlTw8qEd4cYU= 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=h7/OobJg; arc=fail smtp.client-ip=40.107.243.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="h7/OobJg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I3GIwY1ZEKBYeNMEMWO0BD5sgrYHPH4vudQUW7bTw1uu7OFNg7/v7XoZuVXJXxbTvQy2fHn9SHiywuaZFjromQcQCFGuC8QtFmqTnJt5klTEJHlorT50RxHWVkPuTqYQQ+1GzqZxx7p4myenKg/CUq90PY9z7scacK3QvUYHzD4naIzcyDyyTHA1Pw/V+6DV1LGITRiI197PTb+vgT3iK5CNu8LhARS2TjAz7PtwBi6UGG3BURwC/U/p2LjhGjQb0qukg7cncrsavJiJVTH+nWevnOSUor56BEzIGSHDWQ6VdAyqC2cWPKsNkCMs97H/lyE2QiB7C+fRbZK7kvQT+w== 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=fNt9TmuA9yI8ZhNJJ7w30rKg+A7brVx94MewFjpakdo=; b=M0JYnpTWrLFbO7qKv88TXF2XCGLsJQycWI4o8glbM3XAnTQ8yamBpdB/Y71wVD2LHSHO2TlDy7fuGwrg9OoqnIBeKoALBb/esT//o+sOd3AgwpAng+1fq3NS0opnYMV44C4T7q8bO8R+ed5C75UMPfoR4MfEA9LwwkFUUHY3Sy2jEyWFzUMJM/fS4MEiU2codAl4zgptktVpUYc9UGt52BaHpKy6pSNbe5TD8LkLabO+ATBRk3sgAXzmD0O3onL08KnJrTnBbk7nhnYVaLTyuaTqtNYZ4lnjkrvfsx3ueMoaIlpEJwMok2xiXkl5zApBju26hQ1yA173jmYsSqcY8w== 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=fNt9TmuA9yI8ZhNJJ7w30rKg+A7brVx94MewFjpakdo=; b=h7/OobJg6JO1ShO80JzpVvgEGPk4eZH5Gz2q+BRdBtsVYZO8Mmh8N8f+LLBIM87MWiOrlS3TpzC2pQfBqi8Qrm0uNHC+bAAwO/678/+Cu3EUPHyXZ1jJgUuaGBecXQHXKJOOUz1K96OpIQsBKmn6CJgzOtfijP3RKy3KkLUfp0jJem8KEmuHv0SMcOMKPgzp1dVX9CA7sZ8U0XhrfEdeI6cLC9DI1jJrUA0YK2nGR8MgEySJeUeXmvQsbeT+DQufRGrX672QRwihtmfzwPGOxrwD4c1tILOWlRsgKheIOUFVpFm+fzooE1a/Hj554+qGpBD3bePgvWROSN8TP+ROfw== Received: from BYAPR11CA0091.namprd11.prod.outlook.com (2603:10b6:a03:f4::32) by SJ1PR12MB6265.namprd12.prod.outlook.com (2603:10b6:a03:458::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.32; Mon, 22 Jan 2024 08:46:44 +0000 Received: from MWH0EPF000989E9.namprd02.prod.outlook.com (2603:10b6:a03:f4:cafe::80) by BYAPR11CA0091.outlook.office365.com (2603:10b6:a03:f4::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.32 via Frontend Transport; Mon, 22 Jan 2024 08:46: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 MWH0EPF000989E9.mail.protection.outlook.com (10.167.241.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Mon, 22 Jan 2024 08:46: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; Mon, 22 Jan 2024 00:46:30 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.231.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; Mon, 22 Jan 2024 00:46:24 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next 7/9] ethtool: cmis_cdb: Add a layer for supporting CDB commands Date: Mon, 22 Jan 2024 10:45:28 +0200 Message-ID: <20240122084530.32451-8-danieller@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240122084530.32451-1-danieller@nvidia.com> References: <20240122084530.32451-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E9:EE_|SJ1PR12MB6265:EE_ X-MS-Office365-Filtering-Correlation-Id: ffc06a8c-3955-4c56-c8ba-08dc1b26a969 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eYey39RW63IZZQJ5ntU4xGvnHSInaOz5YzVH39r9n1QKc/D+1tLWj8FFS+pndcL666pZueUl5xm1wtBGgqVkCv3fc2tr9cHdA3yt/kSblrHG93a1S2HFDs7XmVTxvhPlSsGpM/p4bqCGiX7ZpaZW+Q1u850GCO02YIX61vQbf7dxVkwaNsVfM5d5OHI3R0zJf34FRpm3lGFF+FJXvVrHuvrQjvn1Pz9NDuKyW4X7AuHhJV7451HepkA4ZRJjgFWGsDmaAjDsphp3KrSCb2ms3E4Vt3Oaqx7HGL30t+MYQaTtvByiCwza7jdFi4efoDb/lwemW/v2fdrKQ6PL6nQKaBZKP45h49P4/lI1H3ddWOhUELV4ihj2i86l5Vr462efzS4bRBBI6RXoOM06R/ofDmMriIO1fY15ZLnq0NVo7MnHOajACx2Dz5tc5qPNb1bC3SQf94eOBgOWeD/Y2Sfxjg50clsESjfNkWJed7xjSqYcMnlJLkxP8mRJf8nqQF5xL0uiBf03HN1R05amtJ3+L7dPEalf9ZaJN48Tfhr8clS2esLXpF2RxorE/0HqK7FU3pLYxBYuvTjtDL66K+MzpbhJij4jrrZMipvXJ11c1FeXTBCfq3Ut0PDsQ84f7c//NAA+4GWRkaitRiycZ/arVLfMelrmldWJZbXT2iD0Ut11Qi1GjcRPnb3gfpNrIHEWCi4mkV+BKe+976wBUwgzP3GE691kJAXsNMQtCokwyl180yVwhloOl2skkFtVCU6f 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)(186009)(82310400011)(451199024)(1800799012)(64100799003)(46966006)(36840700001)(40470700004)(1076003)(107886003)(26005)(16526019)(36756003)(2616005)(36860700001)(336012)(426003)(41300700001)(83380400001)(47076005)(70206006)(2906002)(70586007)(6916009)(54906003)(316002)(30864003)(478600001)(40460700003)(8676002)(4326008)(8936002)(5660300002)(40480700001)(7416002)(86362001)(82740400003)(7636003)(356005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2024 08:46:44.3038 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ffc06a8c-3955-4c56-c8ba-08dc1b26a969 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: MWH0EPF000989E9.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6265 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 --- net/ethtool/Makefile | 2 +- net/ethtool/cmis.h | 112 ++++++++ net/ethtool/cmis_cdb.c | 563 ++++++++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 12 + 4 files changed, 688 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..a8d6f96ed26f --- /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); + +int 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..b27e12871816 --- /dev/null +++ b/net/ethtool/cmis_cdb.c @@ -0,0 +1,563 @@ +// 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; +} + +int 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; + page_data->data = kmalloc(page_data->length, GFP_KERNEL); + if (!page_data->data) + return -ENOMEM; + + return 0; +} + +void ethtool_cmis_page_fini(struct ethtool_module_eeprom *page_data) +{ + kfree(page_data->data); +} + +#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; + + err = ethtool_cmis_page_init(&page_data, CMIS_REVISION_PAGE, + CMIS_REVISION_OFFSET, sizeof(*rpl)); + if (err < 0) + return err; + + 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 cmis_rev_rpl *)page_data.data; + *rev_major = cmis_rev_rpl_major(rpl); + +out: + ethtool_cmis_page_fini(&page_data); + return err; +} + +#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 netlink_ext_ack extack = {}; + struct cmis_cdb_advert_rpl *rpl; + int err; + + err = ethtool_cmis_page_init(&page_data, CMIS_CDB_ADVERTISEMENT_PAGE, + CMIS_CDB_ADVERTISEMENT_OFFSET, + sizeof(*rpl)); + if (err < 0) + return err; + + 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 cmis_cdb_advert_rpl *)page_data.data; + if (!cmis_cdb_advert_rpl_inst_supported(rpl)) { + err = -EOPNOTSUPP; + goto out; + } + + cdb->read_write_len_ext = rpl->read_write_len_ext; + +out: + ethtool_cmis_page_fini(&page_data); + return err; +} + +#define CMIS_PASSWORD_ENTRY_PAGE 0x00 +#define CMIS_PASSWORD_ENTRY_OFFSET 0x7A + +struct cmis_password_entry_pl { + u32 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_cdb_query_status_rpl *rpl; + struct ethtool_cmis_cdb_cmd_args args; + struct cmis_password_entry_pl *pe_pl; + struct netlink_ext_ack extack = {}; + int err; + + err = ethtool_cmis_page_init(&page_data, CMIS_PASSWORD_ENTRY_PAGE, + CMIS_PASSWORD_ENTRY_OFFSET, + sizeof(*pe_pl)); + if (err < 0) + return err; + + 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); + goto out; + } + + 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"); + goto out; + } + + 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"); + err = -EINVAL; + } + +out: + ethtool_cmis_page_fini(&page_data); + return err; +} + +/* 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; +} + +#define CMIS_LOWER_PAGE 0x00 +#define CMIS_BYTE_LENGTH 1 + +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; + + err = ethtool_cmis_page_init(&page_data, CMIS_LOWER_PAGE, offset, + CMIS_BYTE_LENGTH); + if (err < 0) + return err; + + 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)) + goto out; + + if (*cond_fail && (*cond_fail)(rpl->state)) + break; + + } while (time_before(jiffies, end)); + + err = -EBUSY; + +out: + ethtool_cmis_page_fini(&page_data); + return err; +} + +#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_get_reply(struct net_device *dev, + struct ethtool_module_eeprom *page_data, + u8 rpl_exp_len, struct netlink_ext_ack *extack) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + + page_data->offset = CMIS_CDB_REPLY_OFFSET; + page_data->length = rpl_exp_len; + page_data->i2c_address = ETHTOOL_CMIS_CDB_PAGE_I2C_ADDR; + page_data->page = ETHTOOL_CMIS_CDB_CMD_PAGE; + + return ops->get_module_eeprom_by_page(dev, page_data, extack); +} + +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); + struct netlink_ext_ack extack = {}; + struct ethtool_cmis_cdb_rpl *rpl; + int err; + + if (!args->rpl_exp_len) + return 0; + + err = cmis_cdb_get_reply(dev, page_data, + args->rpl_exp_len + rpl_hdr_len, &extack); + if (err < 0) { + if (extack._msg) + netdev_err(dev, "%s\n", extack._msg); + return err; + } + + 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) + return -EIO; + + args->req.lpl_len = rpl->hdr.rpl_len; + memcpy(args->req.payload, rpl->payload, args->req.lpl_len); + + return 0; +} + +static int +__ethtool_cmis_cdb_execute_cmd(struct net_device *dev, + struct ethtool_module_eeprom *page_data, + u32 offset, u32 length, void *data) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + struct netlink_ext_ack extack = {}; + int err; + + page_data->offset = offset; + page_data->length = length; + + memset(page_data->data, 0, ETHTOOL_CMIS_CDB_LPL_MAX_PL_LENGTH); + 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); + } + + 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; + } + + err = ethtool_cmis_page_init(&page_data, ETHTOOL_CMIS_CDB_CMD_PAGE, 0, + ETHTOOL_CMIS_CDB_LPL_MAX_PL_LENGTH); + if (err < 0) + return err; + + /* 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, offset, + sizeof(args->req.body), + &args->req.body); + if (err < 0) + goto out; + + offset = CMIS_CDB_CMD_ID_OFFSET + + offsetof(struct ethtool_cmis_cdb_request, id); + err = __ethtool_cmis_cdb_execute_cmd(dev, &page_data, offset, + sizeof(args->req.id), + &args->req.id); + if (err < 0) + goto out; + + err = cmis_cdb_wait_for_completion(dev, args); + if (err < 0) + goto out; + + err = cmis_cdb_wait_for_status(dev, args); + if (err < 0) + goto out; + + err = cmis_cdb_process_reply(dev, &page_data, args); + +out: + ethtool_cmis_page_fini(&page_data); + return err; +} diff --git a/net/ethtool/module_fw.h b/net/ethtool/module_fw.h index 36cb0bc85526..a4d4220db35d 100644 --- a/net/ethtool/module_fw.h +++ b/net/ethtool/module_fw.h @@ -8,3 +8,15 @@ 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 + * @file_name: Firmware image file name. + * @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 { + const char *file_name; + u32 password; + u8 password_valid:1; +}; From patchwork Mon Jan 22 08:45:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13524936 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2079.outbound.protection.outlook.com [40.107.220.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 77A2739870; Mon, 22 Jan 2024 08:46:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913212; cv=fail; b=CRd3DCCPKDDCD3XKQA/mDxVaKbfrUOkLdGpBDv7KQUk8E8PnsNNyo0M2R35fvBnfkb3J3IveebDH0mCb0dNhV/scONp2NpJBPyk3a2RN25dr81Iz6zRP6/qLd/WCrasCPCMhm8Kur4rUQV82soWdMsrEo9VPVLkUHi6SotlKPVk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913212; c=relaxed/simple; bh=2wKmwfxzyCrc+jqF+e3sHVs0hw7DmZO5BBD0c1Vf6sg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ab3Wzs8/SXAZI7qvAgQ4Y2TCPG3kFodGBFcy8lsyU27aefLB3jA2hBQP8dX/sYWz41No+u2nGc8sRjFljIYImojoLx7WlwyyECOM8u23AIfSf7il0Pr3BToq2n3S11qM5RGg9s21ygu9UiF52ENV/0Cg7pylAfHrllrJUY2tXw4= 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=FWd5mMFc; arc=fail smtp.client-ip=40.107.220.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="FWd5mMFc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NB+FnCazFY+YnRyBtKCDTgFl7a+gwW7w7RBqVJM2/i8sfBbRRN+B4DZd7dglhmPMLSQtkP6hvfQwCsB/1I2mni7QkyL0oDwYwiz0g4nqpmz4asNIEPihxdakfBZqn8COE+8piQ0P/x0Zabepn6nxyL3rb3sLeLYVfOj+6ITjjZdylLy1HUx2UmIW66Fc/0VQ3/GIBs7PePPRvTfDKTvUCdS5yIFgHF/gUK7DQD+dtGDax61Xh/sUnb4U5IsnqL+v6Rp/1SoBeKBc3y8X/hUypdy8yTfX7SqIkjf9snflqmdpjxhNTDECtHZKzMiFsSJJvVjynNzPV89f6tFPukCqFA== 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=dpwukNwzsvY826dbZP6FQ9LZ7jOsQFtO+AzINp6Y+l0=; b=ItW9l/zxB/z8FFzaETAmGqEWpYXkhfVq5DoxpMbzynmmKHl9Nq1SWgpXdzmCyqhSd/xefUgKWnbDbu6sui4J8afkWO6yfn+ZXSpijemLwuZ2z1cwkh4DEMIwoJNZq0eACV2EQDG06ik2FA1Rx77As3FrGDcfADh2vw9L+zHw5IGYNBFumNUyeXsr5GLGbELUisBlf8jce6I2MGwQvnaGCj4pmcRnNeva9homdIOSWs4M2QeeLtwuEsHmDPKcSTaD4dHmWjjVQady/1VSi1LELYlZ8noMEbFkJqddYElIg4WeCLBnvQgz2lA1WalskFCtxG0C2gLtHo6oqIA57qhChg== 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=dpwukNwzsvY826dbZP6FQ9LZ7jOsQFtO+AzINp6Y+l0=; b=FWd5mMFc5XvPS7bKHf15iLz7Ht46Zg8OiTYfOJ2mMPAvwzAzR2vvj8/ggzVHiSOWRrlEq2VYju4DBe6V2iU7bgxmJd+B07NYThXVF4P3I2L5sY1hjl/Tb5iSULqkemic9m5H+AijeBm3ftPAvEVvdAQgDIRpZPpYMEyurLaZJ4z5QHe/Okv6m2PLC+2FVfQ4kJ1KLuAYpro0WTA2Su5Wn52pC5IDyuJezV5g746qLuQKQw4+zULxdZcSol/p6RinE9PJekXynrULpx55UZ6FmJRRPCUj7dwaQPkKxHKmJ3+7TOCcd4eIrNE461p9DiD+2acDT2e2w4JI5bkQ17ve2A== Received: from DS7PR03CA0175.namprd03.prod.outlook.com (2603:10b6:5:3b2::30) by SA1PR12MB7293.namprd12.prod.outlook.com (2603:10b6:806:2b9::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.31; Mon, 22 Jan 2024 08:46:47 +0000 Received: from DS3PEPF000099DC.namprd04.prod.outlook.com (2603:10b6:5:3b2:cafe::ba) by DS7PR03CA0175.outlook.office365.com (2603:10b6:5:3b2::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.34 via Frontend Transport; Mon, 22 Jan 2024 08:46:47 +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 DS3PEPF000099DC.mail.protection.outlook.com (10.167.17.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Mon, 22 Jan 2024 08:46:47 +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; Mon, 22 Jan 2024 00:46:35 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.231.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; Mon, 22 Jan 2024 00:46:30 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next 8/9] ethtool: cmis_fw_update: add a layer for supporting firmware update using CDB Date: Mon, 22 Jan 2024 10:45:29 +0200 Message-ID: <20240122084530.32451-9-danieller@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240122084530.32451-1-danieller@nvidia.com> References: <20240122084530.32451-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DC:EE_|SA1PR12MB7293:EE_ X-MS-Office365-Filtering-Correlation-Id: 3f460476-ba5e-437e-a871-08dc1b26ab26 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: okvghLRWL2neWaML0z2h8QumbD+HqWqX+mNB1qAMM/6/MGShiaJo7D6HLc2wzzKdnEcCZWr/QFjX83CoIeepTPhOUOAcIyDQmNA8eWiEsvpDFfnqdMBSazI90h3XAk6q5X8STDy/AVX5Z6DMwEsTNWOScBqzwiWe/yeAVK0lYqeZIAgjmGk1dmzZXjKbztSr5jtFKaqR5AGlkCqOmPJpWQVhpP56WC93hc4VPlrZi0dEYm/PwG53mbt7mH2scYA490Nvl1ZQDmtv7MTvUESfb74kBPZrbgkrR9S5SiQKa6J+HgVAW0k/hvwALTl4O/OFJm7KVxz7te1xirwK4zV+EInoQLKYVU0qckNg6g8NPMcGO7MgjJ3grkXnLGG2kSTUlD9sn5snw/AeGtFBsoXu+rm3sg4+ankga5S3k+8gExvQocWU57mIVebi2e6yUeqZmAOnuHBaDiqrgkAAiLsHT4bJ+HuDfiszh8tFB/jyrTI49+VjI36g9Fx1VKZc26/+SsMBlFmhOeNj6XTLi7Z8rXdjj4KQdjt6OsWfWS44apqsjSiN9GXbnzKQYk41PSkB7npF09iH1S9ot5AN14DJ0FntD58r1Vd8DLgz3RT2T13iKRluya7h2SYeP4Kozw4fq/Jfv5Jg1v/Onal5K3ld0wBM7PZoJDv4hlcegqxjZwx0T6hO7w61bNyN/dU2WWG+vxrnLv/XZCdMWxi0NSeBiunIZS6NhFWANYgDdsOqTmvWZHjFhgnKgsi0MlN5X4SI 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)(396003)(39860400002)(346002)(136003)(376002)(230922051799003)(451199024)(64100799003)(186009)(1800799012)(82310400011)(40470700004)(46966006)(36840700001)(41300700001)(336012)(107886003)(1076003)(426003)(40460700003)(40480700001)(26005)(16526019)(82740400003)(36756003)(36860700001)(47076005)(478600001)(2616005)(83380400001)(7636003)(356005)(15650500001)(5660300002)(70586007)(54906003)(70206006)(316002)(30864003)(8936002)(86362001)(2906002)(4326008)(7416002)(8676002)(6916009);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2024 08:46:47.2506 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3f460476-ba5e-437e-a871-08dc1b26ab26 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: DS3PEPF000099DC.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7293 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 --- net/ethtool/Makefile | 2 +- net/ethtool/cmis.h | 7 + net/ethtool/cmis_fw_update.c | 371 +++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 18 ++ 4 files changed, 397 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 a8d6f96ed26f..dd1ac13c5e25 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..6ecaaf6cccda --- /dev/null +++ b/net/ethtool/cmis_fw_update.c @@ -0,0 +1,371 @@ +// 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_cdb_init; + + 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_fw_mng_features_get; + + err = cmis_fw_update_download_image(cdb, module_fw, &fw_mng); + if (err < 0) + goto err_download_image; + + err = cmis_fw_update_run_image(cdb, module_fw); + if (err < 0) + goto err_run_image; + + /* 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_cdb_init; + + err = cmis_fw_update_commit_image(cdb, module_fw); + if (err < 0) + goto err_commit_image; + + ethnl_module_fw_flash_ntf_complete(module_fw->dev); + ethtool_cmis_cdb_fini(cdb); + goto out; + +err_commit_image: +err_run_image: +err_download_image: +err_fw_mng_features_get: + ethtool_cmis_cdb_fini(cdb); +err_cdb_init: + ethnl_module_fw_flash_ntf_err(module_fw->dev, NULL); +out: + netdev_put(module_fw->dev, &module_fw->dev_tracker); + module_fw->dev->module_fw_flash_in_progress = false; + release_firmware(module_fw->fw); + kfree(module_fw); +} +EXPORT_SYMBOL_GPL(ethtool_cmis_fw_update); diff --git a/net/ethtool/module_fw.h b/net/ethtool/module_fw.h index a4d4220db35d..969de116f995 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 * @file_name: Firmware image file name. @@ -20,3 +22,19 @@ struct ethtool_module_fw_flash_params { u32 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 Mon Jan 22 08:45:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13524937 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2077.outbound.protection.outlook.com [40.107.102.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 8686838FB7; Mon, 22 Jan 2024 08:47:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913225; cv=fail; b=WQ2HIQzbv8dsK5oj8RouOD3PIIfGSHh8BuIGXSUtfynr1dBozlSOMjH33Bb8QtTrSqLqm+LOppHad4bFc/MKen8R/V9Wdz/xof0UEeEsoKtE+x8ICh3uV4HnUQD4AIc6xSE9qVx0Ibt64oNDffZHwWfeNUtVdNTFy2hgKbqqgR8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913225; c=relaxed/simple; bh=MbRK6/zyypZDras7Ojni4hWbgIISVYMN8+1fiHTEfnc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XBgj+NWrfgdhVRBHvC5B7sPO9ethgEWRnsthiNIqXWJjxuGDPWeqgRxz8VzVsgCrWgTBdacsZeGSeHaJyCbAzBxRQ5xmbRPhUYD4Ly81HvXZQ2MsUS54bSbLZNNgrfuVm9UkK2w2dAeAaaekyfHUL0W2Agg687IlxR0MfUWdmJM= 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=QM3ZNe09; arc=fail smtp.client-ip=40.107.102.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="QM3ZNe09" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QbOtqSVIe67vuxG7Xlzjj8dP4uxtXojxgMKC5HYqRK5UIfF5B8BHy8HHRyoKHvUAtBkbf2tq11seQt4G+59zcNiE29zEUMBL4/zhkl2ePAM0Q5n6fKwGMbIfhBjZ3RmNCf8SEzyQuHrmpuqBVFu58HLshC8+qpqJlctreHQ/CJA6xsMySFoJMpNSi/HWC2t0Fq2UGXbIMj7mUbW1F7KNUTbGKXnIxBUFRmfGdR17FLK0oDLpdi27+eabOnqEgAnMHev9K5Z4vk8wDrw+X4BJlp2ppMN42pKrz1097MuOjudRDsDIr5LUVc5szlg2h5koq/ZyD2uPxxnt3M/t1VBAJw== 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=HlURVs4NqzvyjS99PltohAtgRthKnFTlg52pIs82LPo=; b=hTpE5fjZBbmEfyHHjgYkwF0kF6gvuEk7E0SaTjxZyUNGoAQ1OTmwJeUq4qK6pXQ/VQUNcNyOp1SxqRq1eDfm7UwjO+ptpG1aarwhSPLxmJjRxblESfxcReNYiAUZaD3F+QShZCrdgjhFi2QCDWyYMz5gIf4LmwG1r5yoxDee5GE5Nt+59i8uWpwx3spWAQShiUv5v8CLl+PljXHvq4IzzgkVTF03BAJvlQ68ZsGR7BtB29fg/T8MVFLe+5hGzOqDf9ts4FY4RfGx9v22bK9bYdtUDFrq53OkRQQoVt4H7b5xnLAvw0vDvdp8OhanPeh8zTfjko5sgFYmw88A13cALQ== 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=HlURVs4NqzvyjS99PltohAtgRthKnFTlg52pIs82LPo=; b=QM3ZNe09I0/QMJ97nuDqEAXKp/fMd6kX4q+SelETlcyeTkZ3vO+biwyS9lSZepUXFuqFN7/pthWsMcNqtPL7b65rxYWM28ouBLENzRmyrt5lBJmN66dD2WTiT+XgAfH4CmCWYklrJ900SOotUVrfjx0MrzTQx6hfc7hSqINfuI8/8dHWrZ/GojNsmN74kYlEk2r4R8hrdfJJU34VwxWLonbZ/WkUokTPpov4ZFklEKW33Z/zdcdXf1bG32f0zkijZmLEwc/sWf3LijMjEbRrGHwBi7R3mQ8YbB+IpKmCHASrl627wExWJ0gwNNFnazvV0ZS2jcJoPNOBfqUoKtiHBQ== Received: from BYAPR11CA0095.namprd11.prod.outlook.com (2603:10b6:a03:f4::36) by SA3PR12MB9179.namprd12.prod.outlook.com (2603:10b6:806:3a1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.32; Mon, 22 Jan 2024 08:46:59 +0000 Received: from MWH0EPF000989E9.namprd02.prod.outlook.com (2603:10b6:a03:f4:cafe::9b) by BYAPR11CA0095.outlook.office365.com (2603:10b6:a03:f4::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.32 via Frontend Transport; Mon, 22 Jan 2024 08:46:59 +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 MWH0EPF000989E9.mail.protection.outlook.com (10.167.241.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Mon, 22 Jan 2024 08:46:59 +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; Mon, 22 Jan 2024 00:46:42 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.231.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; Mon, 22 Jan 2024 00:46:36 -0800 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [RFC PATCH net-next 9/9] ethtool: Add ability to flash transceiver modules' firmware Date: Mon, 22 Jan 2024 10:45:30 +0200 Message-ID: <20240122084530.32451-10-danieller@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240122084530.32451-1-danieller@nvidia.com> References: <20240122084530.32451-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E9:EE_|SA3PR12MB9179:EE_ X-MS-Office365-Filtering-Correlation-Id: 7fb4c890-756a-4df2-ff37-08dc1b26b23d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g5raV8CKTqI8AK9lMTCVnAb03/+u/QPGdsZ25O0dKlHf3+kirMXRO8/2ozT7KLSLrx6K8+8msTPDt9sLymsxcM8QVu6P9x6mO95KulS1HpP1uNjBpRl3/IWO8X2d2lKQatLeNbgokUbmE0qX3buY+yRNES2ffy6goRmAxANEZwTSTWSBoryTn8mLO+jap9pVUJe+4AlbK5JaAf/fJvTcTyhbpuUXWVmBvipe8BHuRBe3xRlwcOHS2CTD3gKKg2jHbVhcOL9V/9TCus35c5F8aXp+0U+NSANJ5IDXbZNvKy42UeSeJIfKy/osF2t3F5M/U2qRZGTfIccAhfKuMAT0W4W+pTzY7FyIS6nP45O81u4Qu49tng/xW0kVW7QeHZ2dae5LbKSonzbGr77BKDI41VmrQVDdAWgrIpgHay1uKunzMSkvzbW9AH1SvveBZ5VJ+dMeouDdj635cNauWKOkBNyXEkqRDHn3n5j5upoGccq0XPNe6YI/Nn8W2oYK3h70YF2M+U0FJX+Zql7lFja4CbBmglfNH7BEZ6mFEBxmgVex/w+0m1KUgCK/udcJMoNYKC4ca8QAOFssy1J30fkh57Kzwhy1jSNISezGSaTsM9MM41zW8bUxqYiNlRcLc1KKogBc1sITI2bpxVNw9YjGnm63v11IiIubSuS5M4RHxP73ziFEBHHvBgJP/qvl6bThF87l+KoebrsogUGn/6CGJYR3Q2FoOEhXD8y5MphFlonaDw0KyrH/Q17CStuUOMLF 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)(39860400002)(136003)(346002)(376002)(230922051799003)(186009)(82310400011)(64100799003)(451199024)(1800799012)(40470700004)(36840700001)(46966006)(40460700003)(40480700001)(83380400001)(36756003)(86362001)(356005)(7636003)(82740400003)(36860700001)(5660300002)(8936002)(8676002)(4326008)(47076005)(2616005)(1076003)(336012)(107886003)(426003)(26005)(16526019)(70206006)(70586007)(6916009)(54906003)(316002)(41300700001)(6666004)(478600001)(7416002)(2906002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2024 08:46:59.1319 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7fb4c890-756a-4df2-ff37-08dc1b26b23d 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: MWH0EPF000989E9.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9179 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the ability to flash the modules' firmware by implementing the interface between the user space and the kernel. Example from a succeeding implementation: # ethtool --flash-module-firmware swp40 file test.bin Transceiver module firmware flashing started for device eth0 Transceiver module firmware flashing in progress for device eth0 Status message: Downloading firmware image Progress: 0% [...] Transceiver module firmware flashing in progress for device eth0 Status message: Downloading firmware image Progress: 50% [...] Transceiver module firmware flashing in progress for device eth0 Status message: Downloading firmware image Progress: 100% Transceiver module firmware flashing completed for device eth0 Signed-off-by: Danielle Ratson --- net/ethtool/module.c | 179 ++++++++++++++++++++++++++++++++++++++++++ net/ethtool/netlink.c | 7 ++ net/ethtool/netlink.h | 2 + 3 files changed, 188 insertions(+) diff --git a/net/ethtool/module.c b/net/ethtool/module.c index 09cf11564840..69cedb3ede6d 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,183 @@ 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 }, +}; + +struct module_sff8024_id_rpl { + u8 id; +}; + +#define MODULE_EEPROM_PAGE 0 +#define MODULE_EEPROM_OFFSET 0 +#define MODULE_EEPROM_LENGTH 1 +#define MODULE_EEPROM_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 = {}; + struct module_sff8024_id_rpl *rpl; + 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_PAGE; + page_data.offset = MODULE_EEPROM_OFFSET; + page_data.length = MODULE_EEPROM_LENGTH; + page_data.i2c_address = MODULE_EEPROM_I2C_ADDR; + 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) + goto out; + + rpl = (struct module_sff8024_id_rpl *)page_data.data; + switch (rpl->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); + goto out; + default: + NL_SET_ERR_MSG(extack, + "Module type does not support firmware flashing"); + err = -EOPNOTSUPP; + goto out; + } + +out: + kfree(page_data.data); + return err; +} + +static int +module_flash_fw_schedule(struct net_device *dev, + 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(&module_fw->fw, module_fw->params.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 netlink_ext_ack *extack) +{ + struct ethtool_module_fw_flash_params params = {}; + struct nlattr *attr; + + if (!tb[ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME]) { + NL_SET_ERR_MSG_ATTR(extack, + tb[ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME], + "File name attribute is missing"); + return -EINVAL; + } + + params.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, ¶ms, 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->extack); + + 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];