From patchwork Mon Mar 15 17:12:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 402373 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6491C433E0 for ; Mon, 15 Mar 2021 17:13:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1AD664F21 for ; Mon, 15 Mar 2021 17:13:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235552AbhCORNL (ORCPT ); Mon, 15 Mar 2021 13:13:11 -0400 Received: from mail-co1nam11on2062.outbound.protection.outlook.com ([40.107.220.62]:30560 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231305AbhCORNE (ORCPT ); Mon, 15 Mar 2021 13:13:04 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E6zqxUGTtiGBGhFcNAeKkeFoo8mBDnyplbUAVVIJx00a0TW7whfJeFkz4OoR4AZS4iMg6981wPznoJVv83Zy/1VB95BLJ2Nbyml8QVIiqyelMbDFKt2lwbaD44TZSWN0cF0/sXCIR9DFy6PhTp0/tp9hpCDh30cW1DlGCdAtbGvy5509L2OgVvKhFnqy4MQiyMfUO3nJrjLV2+ob2wIHqZkileCtxiNdbaeC4v8vg4YO+1mgGOf3YZ1h+1nGxJrV3UOVBTsng8GAIaao52UyUdBZEShL9A0mP7ygPJYz/9mnLvpKyvfejvUC918mKnjrOiYgBmjxQ+QwwS0Biez1bw== 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-SenderADCheck; bh=dDkhxdXgtx17Bkot1s+1t4J6BHZFa/DHjRnw+DPLHQM=; b=VSOQskKEJxqI4wG9asssrVAh2PslFluamMcxb5NbJ/WmEOgc62SBcgqjPb36HNcA6tJzGokG1LcDrvo9Isyq3D05JmSfurjX+QmNX+8g20uEX1F56s2JLZF3MbtSWQPnYjbttJM71N/EYeiryiQAfmqwBKlM8qAiw3ZTrLVF7fCNyoTiYJPAFpsqwGvjjhlzpUNolk0gMMnz0gSIzufHBQee2WJ/hr/43Mw7f35nP/N2rwP7xC3r8WpjsqqNk9qRjXVgYxYtg7wF0LZx90+JfUW6yawjfA4LaA4CKOLESgT0H3yb6bOVTqux5/MXhkjfxfJsEOsZQI5ii4UKUE7uZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=suse.cz smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none 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=dDkhxdXgtx17Bkot1s+1t4J6BHZFa/DHjRnw+DPLHQM=; b=rvmHUXMApQDAlzVE9Y68ELWkh1cxp7KM9FuFAeoyrDbvEhVp9YnMWuPA7PWfLg+b3iyVzGshLE4JwTdYzL0Z5Jx9PI0LXn4QVb4ljiIJ1PCwCBFzvW6WSlpyKwrxJu0wDlkIOZ5Tu1XyQgP2/dQkg2vrgkc6aJNruiTaogrOIUuS3FjCjMfzKsgKhgblOrmz4GXL0EepBoYKdtf6fIkyXL8Lyfr2wNY5iv2dzIO6zfsfQ0DMAFAoK9HygjtH8Imk5qwP57WesSP6iRDQ+T5UgqcEXasVXGgM8wcfc7wiFtvh9B28LqrdXZp7JBMZzFchkOcIC/4z+4c+ngfyL+CDPQ== Received: from DM5PR07CA0143.namprd07.prod.outlook.com (2603:10b6:3:13e::33) by DM5PR1201MB0089.namprd12.prod.outlook.com (2603:10b6:4:50::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31; Mon, 15 Mar 2021 17:12:59 +0000 Received: from DM6NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:3:13e:cafe::42) by DM5PR07CA0143.outlook.office365.com (2603:10b6:3:13e::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32 via Frontend Transport; Mon, 15 Mar 2021 17:12:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; suse.cz; dkim=none (message not signed) header.d=none; suse.cz; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by DM6NAM11FT010.mail.protection.outlook.com (10.13.172.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 17:12:58 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 15 Mar 2021 17:12:58 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 15 Mar 2021 17:12:56 +0000 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Adrian Pop , "Michal Kubecek" , Don Bollinger , CC: Vladyslav Tarasiuk , Moshe Shemesh Subject: [RFC PATCH V3 net-next 1/5] ethtool: Allow network drivers to dump arbitrary EEPROM data Date: Mon, 15 Mar 2021 19:12:39 +0200 Message-ID: <1615828363-464-2-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1615828363-464-1-git-send-email-moshe@nvidia.com> References: <1615828363-464-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6c3fa280-3ac7-494a-cd4d-08d8e7d59538 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0089: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H5ocqYpGlAkVrU/n2axoiiMLLkjzHsLqLPO+VF04vugWgSP0nuV+Y5Eu3xuoHKgK6iURVnK09ceipMjcIEh6PvZR8WBfPb6UgpFP8MvbcNJTELqGHK5nDBhSVl5KuflG6iyI4MAVPdGIZN53FYEH7FfG/HXL2EZsIiICE+Ga7bsZn1LKoZppOZ2HnL5URN9c4q+JYyheqY+d95E1/WNs6SuoOwUg6FuyK5RjV12YSMig/lm1Y4dIIHAmD5/JDdmnhgsZ9DSkAmG+j2y7hBCd5Tj7YGr2rTj3P58pC1FIAYAhwjvqAXe0Fp29SaRDJZ3af5Uydo1JZnZ13f4E7m9/3dL0IFcEmuKr/x0mkW7jHBFJqcXUo0mmeFpbzwiyh2cA5Og4yZAGqVNMtTTLiNrxAlDIR8l4JGMlzbl0k+WjIonQFTOcniOJTrleXrsbcWCmAr4RgqALZEVTM8zPmoAxw3CyhBpI3uQWI1HouKzFhVowaCMPk9RT5te7Y64u3JO4wjG0b48zcNRRsJZlcMZKpqOM8S0tteYfk6gLjEvSwYOiX+KxUnRQhxsWXVlIVFvweKlloHQx4H4ctqCDrEXG3EHKtkBMpdtZq2nM6zPksr+ArbBpSmVEDaIIKriQdQ+aMHNnkKjv29PwpBs4lzcaUxBea47T7jxSzEqQQmyymjlATQn41QPlej/Q9A4836+e X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid02.nvidia.com; CAT:NONE; SFS:(4636009)(346002)(136003)(39860400002)(396003)(376002)(46966006)(36840700001)(26005)(70586007)(70206006)(186003)(2906002)(82310400003)(336012)(2616005)(7696005)(426003)(6666004)(356005)(36756003)(107886003)(4326008)(82740400003)(7636003)(47076005)(8936002)(5660300002)(478600001)(36906005)(54906003)(86362001)(30864003)(36860700001)(8676002)(34020700004)(316002)(83380400001)(110136005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 17:12:58.9114 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6c3fa280-3ac7-494a-cd4d-08d8e7d59538 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0089 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladyslav Tarasiuk Define get_module_eeprom_data_by_page() ethtool callback and implement netlink infrastructure. get_module_eeprom_data_by_page() allows network drivers to dump a part of module's EEPROM specified by page and bank numbers along with offset and length. It is effectively a netlink replacement for get_module_info() and get_module_eeprom() pair, which is needed due to emergence of complex non-linear EEPROM layouts. Signed-off-by: Vladyslav Tarasiuk --- Documentation/networking/ethtool-netlink.rst | 34 ++++- include/linux/ethtool.h | 8 +- include/uapi/linux/ethtool.h | 25 +++ include/uapi/linux/ethtool_netlink.h | 19 +++ net/ethtool/Makefile | 2 +- net/ethtool/eeprom.c | 153 +++++++++++++++++++ net/ethtool/netlink.c | 10 ++ net/ethtool/netlink.h | 2 + 8 files changed, 249 insertions(+), 4 deletions(-) create mode 100644 net/ethtool/eeprom.c diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index 05073482db05..25846b97632a 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -1280,6 +1280,36 @@ Kernel response contents: For UDP tunnel table empty ``ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES`` indicates that the table contains static entries, hard-coded by the NIC. +EEPROM_DATA +=========== + +Fetch module EEPROM data dump. + +Request contents: + + ===================================== ====== ========================== + ``ETHTOOL_A_EEPROM_DATA_HEADER`` nested request header + ``ETHTOOL_A_EEPROM_DATA_OFFSET`` u32 offset within a page + ``ETHTOOL_A_EEPROM_DATA_LENGTH`` u32 amount of bytes to read + ``ETHTOOL_A_EEPROM_DATA_PAGE`` u8 page number + ``ETHTOOL_A_EEPROM_DATA_BANK`` u8 bank number + ``ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS`` u8 page I2C address + ===================================== ====== ========================== + +Kernel response contents: + + +---------------------------------------------+--------+---------------------+ + | ``ETHTOOL_A_EEPROM_DATA_HEADER`` | nested | reply header | + +---------------------------------------------+--------+---------------------+ + | ``ETHTOOL_A_EEPROM_DATA_LENGTH`` | u32 | amount of bytes read| + +---------------------------------------------+--------+---------------------+ + | ``ETHTOOL_A_EEPROM_DATA`` | nested | array of bytes from | + | | | module EEPROM | + +---------------------------------------------+--------+---------------------+ + +``ETHTOOL_A_EEPROM_DATA`` has an attribute length equal to the amount of bytes +driver actually read. + Request translation =================== @@ -1357,8 +1387,8 @@ are netlink only. ``ETHTOOL_GET_DUMP_FLAG`` n/a ``ETHTOOL_GET_DUMP_DATA`` n/a ``ETHTOOL_GET_TS_INFO`` ``ETHTOOL_MSG_TSINFO_GET`` - ``ETHTOOL_GMODULEINFO`` n/a - ``ETHTOOL_GMODULEEEPROM`` n/a + ``ETHTOOL_GMODULEINFO`` ``ETHTOOL_MSG_MODULE_EEPROM_GET`` + ``ETHTOOL_GMODULEEEPROM`` ``ETHTOOL_MSG_MODULE_EEPROM_GET`` ``ETHTOOL_GEEE`` ``ETHTOOL_MSG_EEE_GET`` ``ETHTOOL_SEEE`` ``ETHTOOL_MSG_EEE_SET`` ``ETHTOOL_GRSSH`` n/a diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index ec4cd3921c67..9551005b350a 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -81,6 +81,7 @@ enum { #define ETH_RSS_HASH_NO_CHANGE 0 struct net_device; +struct netlink_ext_ack; /* Some generic methods drivers may use in their ethtool_ops */ u32 ethtool_op_get_link(struct net_device *dev); @@ -410,6 +411,9 @@ struct ethtool_pause_stats { * @get_ethtool_phy_stats: Return extended statistics about the PHY device. * This is only useful if the device maintains PHY statistics and * cannot use the standard PHY library helpers. + * @get_module_eeprom_data_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. * * All operations are optional (i.e. the function pointer may be set * to %NULL) and callers must take this into account. Callers must @@ -515,6 +519,9 @@ struct ethtool_ops { const struct ethtool_tunable *, void *); int (*set_phy_tunable)(struct net_device *, const struct ethtool_tunable *, const void *); + int (*get_module_eeprom_data_by_page)(struct net_device *dev, + const struct ethtool_eeprom_data *page, + struct netlink_ext_ack *extack); }; int ethtool_check_ops(const struct ethtool_ops *ops); @@ -538,7 +545,6 @@ int ethtool_virtdev_set_link_ksettings(struct net_device *dev, const struct ethtool_link_ksettings *cmd, u32 *dev_speed, u8 *dev_duplex); -struct netlink_ext_ack; struct phy_device; struct phy_tdr_config; diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h index cde753bb2093..b3e92db3ad37 100644 --- a/include/uapi/linux/ethtool.h +++ b/include/uapi/linux/ethtool.h @@ -340,6 +340,28 @@ struct ethtool_eeprom { __u8 data[0]; }; +/** + * struct ethtool_eeprom_data - 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. + * @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_eeprom_data { + __u32 offset; + __u32 length; + __u8 page; + __u8 bank; + __u8 i2c_address; + __u8 *data; +}; + /** * struct ethtool_eee - Energy Efficient Ethernet information * @cmd: ETHTOOL_{G,S}EEE @@ -1865,6 +1887,9 @@ static inline int ethtool_validate_duplex(__u8 duplex) #define ETH_MODULE_SFF_8636_MAX_LEN 640 #define ETH_MODULE_SFF_8436_MAX_LEN 640 +#define ETH_MODULE_EEPROM_PAGE_LEN 256 +#define ETH_MODULE_MAX_I2C_ADDRESS 0x7f + /* Reset flags */ /* The reset() operation must clear the flags for the components which * were actually reset. On successful return, the flags indicate the diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index a286635ac9b8..e1b1b962f3da 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -42,6 +42,7 @@ enum { ETHTOOL_MSG_CABLE_TEST_ACT, ETHTOOL_MSG_CABLE_TEST_TDR_ACT, ETHTOOL_MSG_TUNNEL_INFO_GET, + ETHTOOL_MSG_EEPROM_DATA_GET, /* add new constants above here */ __ETHTOOL_MSG_USER_CNT, @@ -80,6 +81,7 @@ enum { ETHTOOL_MSG_CABLE_TEST_NTF, ETHTOOL_MSG_CABLE_TEST_TDR_NTF, ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY, + ETHTOOL_MSG_EEPROM_DATA_GET_REPLY, /* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT, @@ -629,6 +631,23 @@ enum { ETHTOOL_A_TUNNEL_INFO_MAX = (__ETHTOOL_A_TUNNEL_INFO_CNT - 1) }; +/* MODULE EEPROM DATA */ + +enum { + ETHTOOL_A_EEPROM_DATA_UNSPEC, + ETHTOOL_A_EEPROM_DATA_HEADER, /* nest - _A_HEADER_* */ + + ETHTOOL_A_EEPROM_DATA_OFFSET, /* u32 */ + ETHTOOL_A_EEPROM_DATA_LENGTH, /* u32 */ + ETHTOOL_A_EEPROM_DATA_PAGE, /* u8 */ + ETHTOOL_A_EEPROM_DATA_BANK, /* u8 */ + ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS, /* u8 */ + ETHTOOL_A_EEPROM_DATA, /* nested */ + + __ETHTOOL_A_EEPROM_DATA_CNT, + ETHTOOL_A_EEPROM_DATA_MAX = (__ETHTOOL_A_EEPROM_DATA_CNT - 1) +}; + /* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool" #define ETHTOOL_GENL_VERSION 1 diff --git a/net/ethtool/Makefile b/net/ethtool/Makefile index 7a849ff22dad..d604346bc074 100644 --- a/net/ethtool/Makefile +++ b/net/ethtool/Makefile @@ -7,4 +7,4 @@ obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.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 + tunnels.o eeprom.o diff --git a/net/ethtool/eeprom.c b/net/ethtool/eeprom.c new file mode 100644 index 000000000000..e110336dc231 --- /dev/null +++ b/net/ethtool/eeprom.c @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include "netlink.h" +#include "common.h" + +struct eeprom_data_req_info { + struct ethnl_req_info base; + u32 offset; + u32 length; + u8 page; + u8 bank; + u8 i2c_address; +}; + +struct eeprom_data_reply_data { + struct ethnl_reply_data base; + u32 length; + u8 *data; +}; + +#define EEPROM_DATA_REQINFO(__req_base) \ + container_of(__req_base, struct eeprom_data_req_info, base) + +#define EEPROM_DATA_REPDATA(__reply_base) \ + container_of(__reply_base, struct eeprom_data_reply_data, base) + +static int eeprom_data_prepare_data(const struct ethnl_req_info *req_base, + struct ethnl_reply_data *reply_base, + struct genl_info *info) +{ + struct eeprom_data_reply_data *reply = EEPROM_DATA_REPDATA(reply_base); + struct eeprom_data_req_info *request = EEPROM_DATA_REQINFO(req_base); + struct ethtool_eeprom_data page_data = {0}; + struct net_device *dev = reply_base->dev; + int ret; + + if (!dev->ethtool_ops->get_module_eeprom_data_by_page) + return -EOPNOTSUPP; + + page_data.offset = request->offset; + page_data.length = request->length; + page_data.i2c_address = request->i2c_address; + page_data.page = request->page; + page_data.bank = request->bank; + page_data.data = kmalloc(page_data.length, GFP_KERNEL); + if (!page_data.data) + return -ENOMEM; + ret = ethnl_ops_begin(dev); + if (ret) + goto err_free; + + ret = dev->ethtool_ops->get_module_eeprom_data_by_page(dev, &page_data, + info->extack); + if (ret < 0) + goto err_ops; + + reply->length = ret; + reply->data = page_data.data; + + ethnl_ops_complete(dev); + return 0; + +err_ops: + ethnl_ops_complete(dev); +err_free: + kfree(page_data.data); + return ret; +} + +static int eeprom_data_parse_request(struct ethnl_req_info *req_info, struct nlattr **tb, + struct netlink_ext_ack *extack) +{ + struct eeprom_data_req_info *request = EEPROM_DATA_REQINFO(req_info); + struct net_device *dev = req_info->dev; + + if (!tb[ETHTOOL_A_EEPROM_DATA_OFFSET] || + !tb[ETHTOOL_A_EEPROM_DATA_LENGTH] || + !tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS]) + return -EINVAL; + + request->i2c_address = nla_get_u8(tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS]); + if (request->i2c_address > ETH_MODULE_MAX_I2C_ADDRESS) + return -EINVAL; + + request->offset = nla_get_u32(tb[ETHTOOL_A_EEPROM_DATA_OFFSET]); + request->length = nla_get_u32(tb[ETHTOOL_A_EEPROM_DATA_LENGTH]); + if (tb[ETHTOOL_A_EEPROM_DATA_PAGE] && + dev->ethtool_ops->get_module_eeprom_data_by_page && + request->offset + request->length > ETH_MODULE_EEPROM_PAGE_LEN) + return -EINVAL; + + if (tb[ETHTOOL_A_EEPROM_DATA_PAGE]) + request->page = nla_get_u8(tb[ETHTOOL_A_EEPROM_DATA_PAGE]); + if (tb[ETHTOOL_A_EEPROM_DATA_BANK]) + request->bank = nla_get_u8(tb[ETHTOOL_A_EEPROM_DATA_BANK]); + + return 0; +} + +static int eeprom_data_reply_size(const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + const struct eeprom_data_req_info *request = EEPROM_DATA_REQINFO(req_base); + + return nla_total_size(sizeof(u32)) + /* _EEPROM_DATA_LENGTH */ + nla_total_size(sizeof(u8) * request->length); /* _EEPROM_DATA */ +} + +static int eeprom_data_fill_reply(struct sk_buff *skb, + const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + struct eeprom_data_reply_data *reply = EEPROM_DATA_REPDATA(reply_base); + + if (nla_put_u32(skb, ETHTOOL_A_EEPROM_DATA_LENGTH, reply->length) || + nla_put(skb, ETHTOOL_A_EEPROM_DATA, reply->length, reply->data)) + return -EMSGSIZE; + + return 0; +} + +static void eeprom_data_cleanup_data(struct ethnl_reply_data *reply_base) +{ + struct eeprom_data_reply_data *reply = EEPROM_DATA_REPDATA(reply_base); + + kfree(reply->data); +} + +const struct ethnl_request_ops ethnl_eeprom_data_request_ops = { + .request_cmd = ETHTOOL_MSG_EEPROM_DATA_GET, + .reply_cmd = ETHTOOL_MSG_EEPROM_DATA_GET_REPLY, + .hdr_attr = ETHTOOL_A_EEPROM_DATA_HEADER, + .req_info_size = sizeof(struct eeprom_data_req_info), + .reply_data_size = sizeof(struct eeprom_data_reply_data), + + .parse_request = eeprom_data_parse_request, + .prepare_data = eeprom_data_prepare_data, + .reply_size = eeprom_data_reply_size, + .fill_reply = eeprom_data_fill_reply, + .cleanup_data = eeprom_data_cleanup_data, +}; + +const struct nla_policy ethnl_eeprom_data_get_policy[] = { + [ETHTOOL_A_EEPROM_DATA_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy), + [ETHTOOL_A_EEPROM_DATA_OFFSET] = { .type = NLA_U32 }, + [ETHTOOL_A_EEPROM_DATA_LENGTH] = { .type = NLA_U32 }, + [ETHTOOL_A_EEPROM_DATA_PAGE] = { .type = NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA_BANK] = { .type = NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS] = { .type = NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA] = { .type = NLA_BINARY }, +}; + diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 50d3c8896f91..ff2528bee192 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -245,6 +245,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_PAUSE_GET] = ðnl_pause_request_ops, [ETHTOOL_MSG_EEE_GET] = ðnl_eee_request_ops, [ETHTOOL_MSG_TSINFO_GET] = ðnl_tsinfo_request_ops, + [ETHTOOL_MSG_EEPROM_DATA_GET] = ðnl_eeprom_data_request_ops, }; static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb) @@ -912,6 +913,15 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_tunnel_info_get_policy, .maxattr = ARRAY_SIZE(ethnl_tunnel_info_get_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_EEPROM_DATA_GET, + .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + .policy = ethnl_eeprom_data_get_policy, + .maxattr = ARRAY_SIZE(ethnl_eeprom_data_get_policy) - 1, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] = { diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 6eabd58d81bf..60954c7b4dfe 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -344,6 +344,7 @@ extern const struct ethnl_request_ops ethnl_coalesce_request_ops; extern const struct ethnl_request_ops ethnl_pause_request_ops; extern const struct ethnl_request_ops ethnl_eee_request_ops; extern const struct ethnl_request_ops ethnl_tsinfo_request_ops; +extern const struct ethnl_request_ops ethnl_eeprom_data_request_ops; extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1]; extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1]; @@ -375,6 +376,7 @@ extern const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_HEADER + extern const struct nla_policy ethnl_cable_test_act_policy[ETHTOOL_A_CABLE_TEST_HEADER + 1]; extern const struct nla_policy ethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_CFG + 1]; extern const struct nla_policy ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_HEADER + 1]; +extern const struct nla_policy ethnl_eeprom_data_get_policy[ETHTOOL_A_EEPROM_DATA + 1]; int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info); int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info); From patchwork Mon Mar 15 17:12:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 402372 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FE03C4332B for ; Mon, 15 Mar 2021 17:14:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64A4C64F3F for ; Mon, 15 Mar 2021 17:14:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235750AbhCORNq (ORCPT ); Mon, 15 Mar 2021 13:13:46 -0400 Received: from mail-bn7nam10on2076.outbound.protection.outlook.com ([40.107.92.76]:6006 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234528AbhCORNI (ORCPT ); Mon, 15 Mar 2021 13:13:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MNI4C1rynJzy6obI04CoubZcvUBZE2+W6jngmUNZpfxoeKYTjIvCx1W1nh/SvAjpi+ZeqG0qXjcWgk05HXpg+aoghQ9pQcRnPTic90tDnq1F8GnA3hSPMsDAWc8OHgVYLwZzqmvQDALGv0b7zZbxDJ1jmAYfZnLIgA7Bsd+rQgtgYZhmBTZsJY4/fNulNtZ5yVvvnLuS3AIlxmAmZRhUG5aMU1q+c9BJ/kyDh00HRvTRDfu9TNxvgKxGtwDsPNCLuw2N1WQli4QajVaPM5H+Tqetir9CcqIC/KvuNix18jMFNX1nhCzFIGrEiWmrYxJnqw5iAqk9xJsayFRCJTbrfQ== 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-SenderADCheck; bh=pSa4YiXXQN5oShlI4zmO7PyWn3gGuDDJ5jnPesOt90A=; b=C1rPqdltVPbyihzEd5oXyRMSGCOA4QdchoJ4TaPocS+Zk7DOc+Bd/wLSHmwB+cJ/kS9UHuMCYh+/5FNKEzP2aIKV7wRjlMXJQyWgwWK7aalRxNXZbBZFg2mD/oLVvlnCkSUhfNuB0fz14iml4gyM5D1Igqw0EDZhk3JYOMzEWb18FtJTMmxHQoW5xHGXK0Z8nVPQOnjtlp54GsIFHWqm9jBOt+pS8cGhZGeUyqjYzWJSdpDK27RY0kvZPZaBuip5qOLMmJKTM9yGXgaA5p0XmS77ce+eTIQ4GCmexl4zAtIaLoDZtcq7Pt9hX4klitK6os/ONMSV/fNSweaKsN+lkQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=suse.cz smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none 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=pSa4YiXXQN5oShlI4zmO7PyWn3gGuDDJ5jnPesOt90A=; b=UfvhGFT05Of2s6pzex4C5FMx+RnOt9Apqf9+QRjprs5DhVKU8lo9SWk8EuLOxWAnjpaFz8HSI+y7o/1kxrb24AqeptGrr1l6bW5owqpcvOT94+EhGTilRqiZ/4E7musZAbLkXyRd3drrzvB+padArvCo50wi3r47lhmV/pjYdYq85xw7SErBLLwcy1sFLW5JPhvdk8f6Y/1UuRgzLjBwAYe724NSy//DxNGC2bXzwfM5bKg+Wvp8BOoI42lFjziX6nvx/0RdezoTJEl7iKC+2Gkm2a33MrvtzkHtknCRJgho7LYfp87FRc6umMqOy5MJW6ecrkln3xExlFBehTyJXQ== Received: from BN9PR03CA0887.namprd03.prod.outlook.com (2603:10b6:408:13c::22) by BY5PR12MB4934.namprd12.prod.outlook.com (2603:10b6:a03:1db::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31; Mon, 15 Mar 2021 17:13:03 +0000 Received: from BN8NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13c:cafe::4a) by BN9PR03CA0887.outlook.office365.com (2603:10b6:408:13c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32 via Frontend Transport; Mon, 15 Mar 2021 17:13:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; suse.cz; dkim=none (message not signed) header.d=none; suse.cz; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT054.mail.protection.outlook.com (10.13.177.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 17:13:01 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 15 Mar 2021 17:13:01 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 15 Mar 2021 17:12:58 +0000 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Adrian Pop , "Michal Kubecek" , Don Bollinger , CC: Vladyslav Tarasiuk , Moshe Shemesh Subject: [RFC PATCH V3 net-next 2/5] net/mlx5: Refactor module EEPROM query Date: Mon, 15 Mar 2021 19:12:40 +0200 Message-ID: <1615828363-464-3-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1615828363-464-1-git-send-email-moshe@nvidia.com> References: <1615828363-464-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0bec0bb6-deb2-4959-aa22-08d8e7d596f2 X-MS-TrafficTypeDiagnostic: BY5PR12MB4934: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1751; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rFuYR5d7xqiGEdK1AsPSbUo8IYt5GOXXrRHg1t7k8RkSq+uj9mK4zzrYO3F2J/i+lyn+ITFfivN88kRzOxSGJ2FiQgCyV6tFAoDL5Tbes58UNJfLVGfqGA4rnQTmX5XOpz+S5wYCrsaOcyGa1Yhq/QOtFMYqe9che+N9wTCkrbiJ7ZgWmRrpNwvzuxlhvUiLbeM5GEAHSnvkF/rhauYZBnCNzJDAO5CHiByBOpIWmkfEPQoBpDwBdlpl2gLOAeqywfwCx9/mR4G2cclRrNOJMyIrYl0Z3PJ/1gfKPMMIiOTPftGQK1fF6R5CGWimpYIy6s5MyOxtOD7H+xpwTU3wbdo7Rlzz3mbTeEXrC053zOu82infQRz+nFBKrLSrCkJv2NA1jURwiv4PWfTQMzP/mmm5UNgq+NUqgGQrnmU0uCPF4fI0dbvfsvO2ilCY7m/Ycp7H+zpPplQxFTF4pT6O5zucB4WNgw3mU3hFHwGqmzDgMB/7OxaT/M8iYDCk/rjqvnvPCqmB1DH51K9ffuJECv0Kmzh0SkFkiVkEu0bjKgfYoyU4HziDmBF1PLmBQAWqGrFSIQgJvATHm2gwvuxHQE0ymx7DRWFG1dHUYZjNljyh7pQ4ziJvuRA8AinmqPDe9hB2IRu4eiYASkGMfc3QEvPu/r6swO/2zOvZZS3f7CBUEXzSCAHMJ6+dHvb1xuer X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(136003)(396003)(376002)(346002)(36840700001)(46966006)(34020700004)(110136005)(107886003)(2906002)(36906005)(316002)(54906003)(82740400003)(82310400003)(7636003)(336012)(356005)(70206006)(2616005)(7696005)(26005)(36756003)(70586007)(478600001)(86362001)(186003)(8676002)(6666004)(83380400001)(36860700001)(4326008)(47076005)(5660300002)(8936002)(426003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 17:13:01.7852 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0bec0bb6-deb2-4959-aa22-08d8e7d596f2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4934 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladyslav Tarasiuk Prepare for ethtool_ops::get_module_eeprom_data() implementation by extracting common part of mlx5_query_module_eeprom() into a separate function. Signed-off-by: Vladyslav Tarasiuk --- .../net/ethernet/mellanox/mlx5/core/port.c | 79 +++++++++++-------- include/linux/mlx5/port.h | 9 +++ 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/port.c b/drivers/net/ethernet/mellanox/mlx5/core/port.c index 4bb219565c58..9b9f870d67a4 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/port.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/port.c @@ -353,67 +353,78 @@ static void mlx5_sfp_eeprom_params_set(u16 *i2c_addr, int *page_num, u16 *offset *offset -= MLX5_EEPROM_PAGE_LENGTH; } -int mlx5_query_module_eeprom(struct mlx5_core_dev *dev, - u16 offset, u16 size, u8 *data) +static int mlx5_query_mcia(struct mlx5_core_dev *dev, + struct mlx5_module_eeprom_query_params *params, u8 *data) { - int module_num, status, err, page_num = 0; u32 in[MLX5_ST_SZ_DW(mcia_reg)] = {}; u32 out[MLX5_ST_SZ_DW(mcia_reg)]; - u16 i2c_addr = 0; - u8 module_id; + int status, err; void *ptr; + u16 size; + + size = min_t(int, params->size, MLX5_EEPROM_MAX_BYTES); + + MLX5_SET(mcia_reg, in, l, 0); + MLX5_SET(mcia_reg, in, size, size); + MLX5_SET(mcia_reg, in, module, params->module_number); + MLX5_SET(mcia_reg, in, device_address, params->offset); + MLX5_SET(mcia_reg, in, page_number, params->page); + MLX5_SET(mcia_reg, in, i2c_device_address, params->i2c_address); - err = mlx5_query_module_num(dev, &module_num); + err = mlx5_core_access_reg(dev, in, sizeof(in), out, + sizeof(out), MLX5_REG_MCIA, 0, 0); if (err) return err; - err = mlx5_query_module_id(dev, module_num, &module_id); + status = MLX5_GET(mcia_reg, out, status); + if (status) { + mlx5_core_err(dev, "query_mcia_reg failed: status: 0x%x\n", + status); + return -EIO; + } + + ptr = MLX5_ADDR_OF(mcia_reg, out, dword_0); + memcpy(data, ptr, size); + + return size; +} + +int mlx5_query_module_eeprom(struct mlx5_core_dev *dev, + u16 offset, u16 size, u8 *data) +{ + struct mlx5_module_eeprom_query_params query = {0}; + u8 module_id; + int err; + + err = mlx5_query_module_num(dev, &query.module_number); + if (err) + return err; + + err = mlx5_query_module_id(dev, query.module_number, &module_id); if (err) return err; switch (module_id) { case MLX5_MODULE_ID_SFP: - mlx5_sfp_eeprom_params_set(&i2c_addr, &page_num, &offset); + mlx5_sfp_eeprom_params_set(&query.i2c_address, &query.page, &query.offset); break; case MLX5_MODULE_ID_QSFP: case MLX5_MODULE_ID_QSFP_PLUS: case MLX5_MODULE_ID_QSFP28: - mlx5_qsfp_eeprom_params_set(&i2c_addr, &page_num, &offset); + mlx5_qsfp_eeprom_params_set(&query.i2c_address, &query.page, &query.offset); break; default: mlx5_core_err(dev, "Module ID not recognized: 0x%x\n", module_id); return -EINVAL; } - if (offset + size > MLX5_EEPROM_PAGE_LENGTH) + if (query.offset + size > MLX5_EEPROM_PAGE_LENGTH) /* Cross pages read, read until offset 256 in low page */ size -= offset + size - MLX5_EEPROM_PAGE_LENGTH; - size = min_t(int, size, MLX5_EEPROM_MAX_BYTES); + query.size = size; - MLX5_SET(mcia_reg, in, l, 0); - MLX5_SET(mcia_reg, in, module, module_num); - MLX5_SET(mcia_reg, in, i2c_device_address, i2c_addr); - MLX5_SET(mcia_reg, in, page_number, page_num); - MLX5_SET(mcia_reg, in, device_address, offset); - MLX5_SET(mcia_reg, in, size, size); - - err = mlx5_core_access_reg(dev, in, sizeof(in), out, - sizeof(out), MLX5_REG_MCIA, 0, 0); - if (err) - return err; - - status = MLX5_GET(mcia_reg, out, status); - if (status) { - mlx5_core_err(dev, "query_mcia_reg failed: status: 0x%x\n", - status); - return -EIO; - } - - ptr = MLX5_ADDR_OF(mcia_reg, out, dword_0); - memcpy(data, ptr, size); - - return size; + return mlx5_query_mcia(dev, &query, data); } EXPORT_SYMBOL_GPL(mlx5_query_module_eeprom); diff --git a/include/linux/mlx5/port.h b/include/linux/mlx5/port.h index 23edd2db4803..90b87aa82db3 100644 --- a/include/linux/mlx5/port.h +++ b/include/linux/mlx5/port.h @@ -62,6 +62,15 @@ enum mlx5_an_status { #define MLX5_EEPROM_PAGE_LENGTH 256 #define MLX5_EEPROM_HIGH_PAGE_LENGTH 128 +struct mlx5_module_eeprom_query_params { + u16 size; + u16 offset; + u16 i2c_address; + u32 page; + u32 bank; + u32 module_number; +}; + enum mlx5e_link_mode { MLX5E_1000BASE_CX_SGMII = 0, MLX5E_1000BASE_KX = 1, From patchwork Mon Mar 15 17:12:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 401000 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65822C433E9 for ; Mon, 15 Mar 2021 17:14:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3AB2364DE2 for ; Mon, 15 Mar 2021 17:14:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235701AbhCORNk (ORCPT ); Mon, 15 Mar 2021 13:13:40 -0400 Received: from mail-mw2nam10on2053.outbound.protection.outlook.com ([40.107.94.53]:16944 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231990AbhCORNK (ORCPT ); Mon, 15 Mar 2021 13:13:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m1fFKf8nH2xMn2s52YAPIDAAnSB6FZ8tvqobGw94gKvfrVfa+XogUDJ123k2Q+14WIVrieUbIXckH5SGEyO61vGoNmkENatSQmGs+su5kyYan3lAhCgoroDoK8ny5yh/u253TXx0b32q0Elot/3kvzXKHZcs6BOYSwn3d9TfqZku78xtkIQoUFTqWPcIWSD3WWrn5RGQpA+DKOk4sM1VWk6wF19a9ePEyFGGXEwq6S+6Fgc1c+1KaCBNMkM5kIAGPXdpJXzVPANQYl/Oo43BiUr5kM8h7JqwKpg8fpGlP+1f/a3BOoc+lsA7CY5i7wUEibHm3OQfz8r9b3lQ/4s8sA== 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-SenderADCheck; bh=vlOlf7CGvFpaGn7oGlnCRWrbU91SO1kegv/bjKV+v/Q=; b=BOw6Dxh0VtLdg7imYdDIfesAsCW7AZVzlE4GVxXYM2nz/mWpondJZVYzl379okOCo6VgeyNGIK0V4x58CX7Qbu9uLyYez/nxqpxe7APG3gwYwdP8H+sGNVZBi+eRjNDLm/X2VZaymZ4KOlVkBr8Tqw9bUizUblzdD0vhYWaIbcU+8g+0nCpc2IjTccOq5iKoTP8RVQSq3k6zzUh2g+iiZWtSDrQ81sHbyFks+74Gf6VXhhEEFLjs0wZSQkUevJncTK6tc6QwrNlJ1xTKoyURluZ7vH56u5U/i6plg1ffj4kv6kgT27OKmVeqxr46khO0DHsvn0CIfAnQDNMGsGDGCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=suse.cz smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none 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=vlOlf7CGvFpaGn7oGlnCRWrbU91SO1kegv/bjKV+v/Q=; b=jC0Pzl4Nu4vqmNOjaIvvI5W8CR0f0zAjYCnPaTabV+xM6XNI1zYjry91jPMPRXwNXydNk0qDewEpqYJ/d3afT6CWReTbE2J7HORVRZ6vxs++aQ37YlNOcti/NDYas2npheM+nfRQ2funiLQ2z9EnmcSnD1DpoGX74hjUi5+oLNbMSTRDX+f7qhRpCRRDgBFqJREVUrBnWbGhZkPdwqoSps8tCU5HPieHdcvhZesQb3jZkdXfDIOq7pYFqif4AeN9zCbsaGO6DwmnGuU0Nh0kBqFei6VLfY7lsC6JW0kveNlUdHPUmFL6K6+/ksfZFIFQ0rULtAjCrgZU7yxs4qabUg== Received: from DM5PR05CA0021.namprd05.prod.outlook.com (2603:10b6:3:d4::31) by BYAPR12MB2677.namprd12.prod.outlook.com (2603:10b6:a03:69::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32; Mon, 15 Mar 2021 17:13:04 +0000 Received: from DM6NAM11FT055.eop-nam11.prod.protection.outlook.com (2603:10b6:3:d4:cafe::a0) by DM5PR05CA0021.outlook.office365.com (2603:10b6:3:d4::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.11 via Frontend Transport; Mon, 15 Mar 2021 17:13:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; suse.cz; dkim=none (message not signed) header.d=none; suse.cz; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by DM6NAM11FT055.mail.protection.outlook.com (10.13.173.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 17:13:04 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 15 Mar 2021 17:13:03 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 15 Mar 2021 17:13:01 +0000 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Adrian Pop , "Michal Kubecek" , Don Bollinger , CC: Vladyslav Tarasiuk , Moshe Shemesh Subject: [RFC PATCH V3 net-next 3/5] net/mlx5: Implement get_module_eeprom_data_by_page() Date: Mon, 15 Mar 2021 19:12:41 +0200 Message-ID: <1615828363-464-4-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1615828363-464-1-git-send-email-moshe@nvidia.com> References: <1615828363-464-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2d385e5c-4e42-4744-e55b-08d8e7d59879 X-MS-TrafficTypeDiagnostic: BYAPR12MB2677: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2733; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u+uFDaE9jj8iXxBtnoJnL5Gys5WU7RDaq+GVDD7yzxElJgctc3yIQMxfunfm6kGX6acMQ72jpq+ivKzmYaTEAMBvdlJSWjKSB0zhdUv9b5pDASEOT0do7iBlUl4mZDHqyLzWL110sS/TFJ2XMIKKaYsQDf1Rg6IGTOLn16uWLzXSL3Jn2j48H7zbnrw9dIpyqDZK/00VQZLHLWKp+CGatWCYvj1mbmTu5gTBOP6EwRKUeElk1Cs/OSkrA+sy35gH2TFfRskDSqtUHv8Zoq7HLuQGSv9cRaHo924l0a9JzFDcirPL5iRmNX5ulOZCGz/+i96EMYH4CCDFSKuxOIuUTBm4PKsnmsB1Tpt5ESmUiN+D42ODRz6JhV1gjxlewDCymRPnTva6irm9bLE30hdRVZcAiu8auYe7LTVAHSC6jNQlvCPbynwMWQLpSBT0CDi0ZfLlPJcabi3lVC749esrAp0P2QItLaEiOQBCgvpCumMsDcW0TrjuSyYxkKhWnjTqoSfW+1esRDD9SJz1z3wTH08ch/Suty5RK3RBlAEVoLsuy2F7P9pIbVorAkd/tsoTfrOX4ZgFaoFRUaJMQVTfpfdVByFKCtm0rJy3SBEUJ2h1zfk0pdJGnE2UHw5rHSnqu6xPd1xEE7DOmEGPzgq4ZhvGp+KXNpU8dmdGUG/6VXes5OVPws4qAd4G3Qa8Qk04 X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(376002)(136003)(346002)(396003)(36840700001)(46966006)(356005)(36860700001)(8936002)(6666004)(8676002)(7696005)(34020700004)(7636003)(478600001)(70206006)(82740400003)(107886003)(83380400001)(47076005)(110136005)(36756003)(86362001)(2616005)(336012)(36906005)(54906003)(316002)(426003)(5660300002)(2906002)(26005)(70586007)(4326008)(186003)(82310400003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 17:13:04.4031 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2d385e5c-4e42-4744-e55b-08d8e7d59879 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT055.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2677 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladyslav Tarasiuk Implement ethtool_ops::get_module_eeprom_data_by_page() to enable support of new SFP standards. Signed-off-by: Vladyslav Tarasiuk --- .../ethernet/mellanox/mlx5/core/en_ethtool.c | 44 +++++++++++++++++++ .../net/ethernet/mellanox/mlx5/core/port.c | 33 ++++++++++++++ include/linux/mlx5/port.h | 2 + 3 files changed, 79 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c index abdf721bb264..5da9edea4d07 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c @@ -1769,6 +1769,49 @@ static int mlx5e_get_module_eeprom(struct net_device *netdev, return 0; } +static int mlx5e_get_module_eeprom_data_by_page(struct net_device *netdev, + const struct ethtool_eeprom_data *page_data, + struct netlink_ext_ack *extack) +{ + struct mlx5e_priv *priv = netdev_priv(netdev); + struct mlx5_module_eeprom_query_params query; + struct mlx5_core_dev *mdev = priv->mdev; + u8 *data = page_data->data; + int size_read; + int i = 0; + + if (!page_data->length) + return -EINVAL; + + memset(data, 0, page_data->length); + + query.offset = page_data->offset; + query.i2c_address = page_data->i2c_address; + query.bank = page_data->bank; + query.page = page_data->page; + while (i < page_data->length) { + query.size = page_data->length - i; + size_read = mlx5_query_module_eeprom_data(mdev, &query, data + i); + + /* Done reading, return how many bytes was read */ + if (!size_read) + return i; + + if (size_read == -EINVAL) + return -EINVAL; + if (size_read < 0) { + netdev_err(priv->netdev, "%s: mlx5_query_module_eeprom_data failed:0x%x\n", + __func__, size_read); + return i; + } + + i += size_read; + query.offset += size_read; + } + + return i; +} + int mlx5e_ethtool_flash_device(struct mlx5e_priv *priv, struct ethtool_flash *flash) { @@ -2148,6 +2191,7 @@ const struct ethtool_ops mlx5e_ethtool_ops = { .set_wol = mlx5e_set_wol, .get_module_info = mlx5e_get_module_info, .get_module_eeprom = mlx5e_get_module_eeprom, + .get_module_eeprom_data_by_page = mlx5e_get_module_eeprom_data_by_page, .flash_device = mlx5e_flash_device, .get_priv_flags = mlx5e_get_priv_flags, .set_priv_flags = mlx5e_set_priv_flags, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/port.c b/drivers/net/ethernet/mellanox/mlx5/core/port.c index 9b9f870d67a4..f7a16fdfb8d3 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/port.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/port.c @@ -428,6 +428,39 @@ int mlx5_query_module_eeprom(struct mlx5_core_dev *dev, } EXPORT_SYMBOL_GPL(mlx5_query_module_eeprom); +int mlx5_query_module_eeprom_data(struct mlx5_core_dev *dev, + struct mlx5_module_eeprom_query_params *params, + u8 *data) +{ + u8 module_id; + int err; + + err = mlx5_query_module_num(dev, ¶ms->module_number); + if (err) + return err; + + err = mlx5_query_module_id(dev, params->module_number, &module_id); + if (err) + return err; + + if (module_id != MLX5_MODULE_ID_SFP && + module_id != MLX5_MODULE_ID_QSFP && + module_id != MLX5_MODULE_ID_QSFP28 && + module_id != MLX5_MODULE_ID_QSFP_PLUS) { + mlx5_core_err(dev, "Module ID not recognized: 0x%x\n", module_id); + return -EINVAL; + } + + if (params->i2c_address != MLX5_I2C_ADDR_HIGH && + params->i2c_address != MLX5_I2C_ADDR_LOW) { + mlx5_core_err(dev, "I2C address not recognized: 0x%x\n", params->i2c_address); + return -EINVAL; + } + + return mlx5_query_mcia(dev, params, data); +} +EXPORT_SYMBOL_GPL(mlx5_query_module_eeprom_data); + static int mlx5_query_port_pvlc(struct mlx5_core_dev *dev, u32 *pvlc, int pvlc_size, u8 local_port) { diff --git a/include/linux/mlx5/port.h b/include/linux/mlx5/port.h index 90b87aa82db3..887cd43b41e8 100644 --- a/include/linux/mlx5/port.h +++ b/include/linux/mlx5/port.h @@ -209,6 +209,8 @@ void mlx5_query_port_fcs(struct mlx5_core_dev *mdev, bool *supported, bool *enabled); int mlx5_query_module_eeprom(struct mlx5_core_dev *dev, u16 offset, u16 size, u8 *data); +int mlx5_query_module_eeprom_data(struct mlx5_core_dev *dev, + struct mlx5_module_eeprom_query_params *params, u8 *data); int mlx5_query_port_dcbx_param(struct mlx5_core_dev *mdev, u32 *out); int mlx5_set_port_dcbx_param(struct mlx5_core_dev *mdev, u32 *in); From patchwork Mon Mar 15 17:12:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 402371 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C34D0C43333 for ; Mon, 15 Mar 2021 17:14:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0CC364DE5 for ; Mon, 15 Mar 2021 17:14:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235796AbhCORNs (ORCPT ); Mon, 15 Mar 2021 13:13:48 -0400 Received: from mail-bn8nam11on2045.outbound.protection.outlook.com ([40.107.236.45]:35639 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235212AbhCORNL (ORCPT ); Mon, 15 Mar 2021 13:13:11 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KEPjBwzx9DYyuCmtlIvYGEkZZXRHdyJ7xNosZZEGqeef9omM4Ab79sSkEK7AwawkPpRJA40r+CnSFCQNj7edzPn14XYjPLOQBEOz8s0VwLty5SkbHb0y0J1h+1frJKZ4K/rnRmOmwcfZQma1SDFbIAG1yhrcdUlWZdxtFfzMjjbs0++eP3bbwCjxOpc1UkOtc9nVbMFeXW48gm4ibyNY3+jY+AKC9FS7N335O2bSd5hmIodAYy1WnY3MjdwqazJLtvaTby9lXVMxW3XHr1JkejoPVZHrAscFIxqfN0kUgs/ZzBxai8WixwydwujbCerAiCdikFCPo98ULpukzAbH0g== 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-SenderADCheck; bh=M4AXX00JemtFWoJmmwbO8NjgibZreYhDao8JxyCWqnY=; b=gK4+ogEem4Yuyl35GchVGiyIsKFrcyYGWeCepsdLZRTVEUfHiA87yBmH7WR4rE3TiFDDzTshe8NDaJfXpALb0z4csX92IoU1fLV6XGn7qERBSFiHkbABX3UaL/ZaZmhSleG91kzx9DVjkJRG2x+m1gzSIBWXk4Npryqe9nyyh+PhUHrHjlbSpED7fvRKHqj2MdOn+qesevBr8S4COfQIVVFM9zgNaXrjxxzYFJxLguXMQIGbl8l2PYHDrPvKfxdztE2H18Oa93ZiQ86SvQhwVN9dfAaaOG5pnlDnG9vWqK1iJgyVNnHH2JNG+WYDWO29ZXsTiMQSah/hEfq54PCUFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=suse.cz smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none 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=M4AXX00JemtFWoJmmwbO8NjgibZreYhDao8JxyCWqnY=; b=A1N+Elk9+BW7OjrB3cIooAHmD1CiGYRiS8dSqh4bSQ4ZIzXVSJIZqldSojjmnCT8S+yc12ZKJKXUen8+/Bw2A95y1Y9GOPqeVppTONQRDk31ctny5OfS51K/6KnGkZj9IOrEDfxY4zMQvsLhPVLrLjq+Ct1MyXJCtK+Ewpx/Iwx/t4P8ktAerWSyTH7EtbT4RbpbRLsQxqUGmf07XSmnPL+000EtOnJQ3kTQmxkiJ/LDI4+ucCizkaYGtoK58PgNrzQl/FGVrPLzj71cGDp5WKzPSeUfQLUFofIasAMU0hYWM4MG7Rj04Qkr+gPIMM8kGK+qKErJuePsBCNomnXHTg== Received: from DM5PR18CA0071.namprd18.prod.outlook.com (2603:10b6:3:22::33) by BN6PR12MB1796.namprd12.prod.outlook.com (2603:10b6:404:106::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31; Mon, 15 Mar 2021 17:13:07 +0000 Received: from DM6NAM11FT059.eop-nam11.prod.protection.outlook.com (2603:10b6:3:22:cafe::c4) by DM5PR18CA0071.outlook.office365.com (2603:10b6:3:22::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32 via Frontend Transport; Mon, 15 Mar 2021 17:13:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; suse.cz; dkim=none (message not signed) header.d=none; suse.cz; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by DM6NAM11FT059.mail.protection.outlook.com (10.13.172.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 17:13:07 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 15 Mar 2021 17:13:06 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 15 Mar 2021 17:13:04 +0000 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Adrian Pop , "Michal Kubecek" , Don Bollinger , CC: Vladyslav Tarasiuk , Moshe Shemesh Subject: [RFC PATCH V3 net-next 4/5] net/mlx5: Add support for DSFP module EEPROM dumps Date: Mon, 15 Mar 2021 19:12:42 +0200 Message-ID: <1615828363-464-5-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1615828363-464-1-git-send-email-moshe@nvidia.com> References: <1615828363-464-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 077aefb2-96c3-4c3b-94e9-08d8e7d59a2e X-MS-TrafficTypeDiagnostic: BN6PR12MB1796: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1201; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jFe5mzlnfQxcG3/liLtThvABT3IZdDtsNxwnVbMl6mY9wNeD5E3iL/iY+rbgfuYpU77UWa5r1TGpPtEI0c1sUIbVMrl5h9sapNOKmGVy2IFXbJ3CyWFoe7k140HE+KkSwmsEHRKZ4fm5unPgkQPXDiHevAfUdlUbQ16G0TUtkXpeia8wfQ80tXAnRHPtz+CjcK0cX1Z3EzjLLCA8kpt9+l0quoYgKybTUb2Wq0wLGbh/paCZ6S9thgq4RUB734vf0gfRg1b4OqsogO9gZX4scq66ZfPzglPkTvSyUw+cCVby1Qtd7ANnV9lQ0tSVeUcszUbJAWKGUYzyb0tK96deK946GbMiOD/uomQQ9llKReKUgCFBzf+7aZFX/LruJpcvuAUjOHFgSCfgNbnO9mPfFe/jmEYCgl0VeId1O8m6ryHCsUubgFDhtTHzqz68Niz6HYMpod5G9HOJqsLYOlUC246DDwsw+8j84dIWf7MfhqRxa6joO05zgGxEdu9WZKzvlSI4W6fhX9scOqPQF8HpGJgAcgz7j/s/0irkzhD6SZunRNNsXOZc6IO7iGMiPWxzoP1ecT02nyKoOPgSYkJwMsfoQidYubr+xCxBcwZm4ocStuRwYT7recHYjsuy2eG9qA0nOSUko3ABai1QMJyRXxTbUrxQ1D6NNiuYv2HKLhgJYi1Xddfp8I0uW4ehLO/1 X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid04.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(396003)(136003)(376002)(346002)(36840700001)(46966006)(34020700004)(107886003)(86362001)(83380400001)(8936002)(478600001)(356005)(36756003)(7636003)(2906002)(26005)(70586007)(5660300002)(110136005)(70206006)(316002)(36906005)(82740400003)(4326008)(8676002)(82310400003)(54906003)(426003)(6666004)(7696005)(186003)(336012)(36860700001)(2616005)(47076005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 17:13:07.2240 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 077aefb2-96c3-4c3b-94e9-08d8e7d59a2e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT059.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1796 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladyslav Tarasiuk Allow the driver to recognise DSFP transceiver module ID and therefore allow its EEPROM dumps using ethtool. Signed-off-by: Vladyslav Tarasiuk --- drivers/net/ethernet/mellanox/mlx5/core/port.c | 3 ++- include/linux/mlx5/port.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/port.c b/drivers/net/ethernet/mellanox/mlx5/core/port.c index f7a16fdfb8d3..3a7aa6b05198 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/port.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/port.c @@ -446,7 +446,8 @@ int mlx5_query_module_eeprom_data(struct mlx5_core_dev *dev, if (module_id != MLX5_MODULE_ID_SFP && module_id != MLX5_MODULE_ID_QSFP && module_id != MLX5_MODULE_ID_QSFP28 && - module_id != MLX5_MODULE_ID_QSFP_PLUS) { + module_id != MLX5_MODULE_ID_QSFP_PLUS && + module_id != MLX5_MODULE_ID_DSFP) { mlx5_core_err(dev, "Module ID not recognized: 0x%x\n", module_id); return -EINVAL; } diff --git a/include/linux/mlx5/port.h b/include/linux/mlx5/port.h index 887cd43b41e8..71b4373cb96c 100644 --- a/include/linux/mlx5/port.h +++ b/include/linux/mlx5/port.h @@ -45,6 +45,7 @@ enum mlx5_module_id { MLX5_MODULE_ID_QSFP = 0xC, MLX5_MODULE_ID_QSFP_PLUS = 0xD, MLX5_MODULE_ID_QSFP28 = 0x11, + MLX5_MODULE_ID_DSFP = 0x1B, }; enum mlx5_an_status { From patchwork Mon Mar 15 17:12:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 400999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8BD7C4332E for ; Mon, 15 Mar 2021 17:14:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B7AD64DFD for ; Mon, 15 Mar 2021 17:14:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235823AbhCORNt (ORCPT ); Mon, 15 Mar 2021 13:13:49 -0400 Received: from mail-bn8nam12on2077.outbound.protection.outlook.com ([40.107.237.77]:23969 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235598AbhCORNO (ORCPT ); Mon, 15 Mar 2021 13:13:14 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NG+6SFkIawg9D5THn4JBLAXJs/RI7Q8w9PSm8GPZP0NHEqMXUykWoBYbI/neXFXQJ3pgymatheeHzZ5A63crSQMbgJR4W747NjoJqf096a+t6MTP/7b3FAec/PL22FAcZv3qE0YR59zImLCwaXB5oj0sq0iDiJsOccl092k1suCn1H8Xe5Gtdaws+WR+Qp2ekv+pjqu2pJWiLVRwlj+oqTkzNGr0ZvvEZvR+8L32tJEm88nAuO6bBCaThpIrMdOBuxqrNmAm47Phzr8hz4/uo2cRYAPtJJX+KSs/8UlKcnvUZczEH85BjEA92K+kkyxjosy9qumTzry2tkozHagbtg== 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-SenderADCheck; bh=NvI0JQDyxIcoltvSXL2aV2GqXQ/S12HykhRkQwkWtDg=; b=SGzvuf5INtKVrCuhsYgR/BZol/QfeSpq5AX8jdPKID9ZPnBL8MARxPVSt8ghR+0dKOuSthy9/iTUU+dtXSq/h21+cOSuVM9GH81XtXaPs5wyJi4VkEwLNMSOa09aUw+i9jY21dcmCheaXpzqatluWMGZFl5FDBVL7Yi+M8DBaIFmrK3TDEDAjVSgXiidgHWjbHD6zAewMSvQMuG7P89g2M3CME192UG9RxF5mmU7wQE/a9vTk1sd3ZNDkzMctPyrSH10wT7X+FfugBJghFIi1YQxcdF4u5CoB3u+twbDLAdBWsCurmQRtBHtikAHwwYDk+jYh5536zTsR6gealf00w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=suse.cz smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none 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=NvI0JQDyxIcoltvSXL2aV2GqXQ/S12HykhRkQwkWtDg=; b=eftbXRMceEH1lXKFUIG9qK6TcQ/A97iCOXg7qCPV3ZE8Jpvh+80G56rsKSkfH1sWdgOxKODv1aOCbgC5R2FyHCNVT/ycU0aQeiqnVDJHDx/qCu6ubblYzZyX4rRc9adJ57Se47ZHrypUk6WphQHgX9Um1oYIiKzlhjHBOw/ornzvLqHoHUJ6uCODQhgvqh2Z0eegHqWIvu+KdnpXnZihSIXFu+AV/iMoRxxbbscMfiZjnvxVvfEKfeLbb24GDqP++0Sw2W562tdbWOuOKukH2wpcIhVX2rPL7KJjtFjq+ptkeJxTSq7m9yEogxxoxnwKX40FWvdh3sElJ2AD9vrffQ== Received: from DM6PR03CA0080.namprd03.prod.outlook.com (2603:10b6:5:333::13) by MN2PR12MB3262.namprd12.prod.outlook.com (2603:10b6:208:102::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31; Mon, 15 Mar 2021 17:13:10 +0000 Received: from DM6NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:5:333:cafe::b6) by DM6PR03CA0080.outlook.office365.com (2603:10b6:5:333::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32 via Frontend Transport; Mon, 15 Mar 2021 17:13:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; suse.cz; dkim=none (message not signed) header.d=none; suse.cz; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by DM6NAM11FT022.mail.protection.outlook.com (10.13.172.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 17:13:10 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 15 Mar 2021 17:13:09 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 15 Mar 2021 17:13:07 +0000 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Adrian Pop , "Michal Kubecek" , Don Bollinger , CC: Vladyslav Tarasiuk , Moshe Shemesh Subject: [RFC PATCH V3 net-next 5/5] ethtool: Add fallback to get_module_eeprom from netlink command Date: Mon, 15 Mar 2021 19:12:43 +0200 Message-ID: <1615828363-464-6-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1615828363-464-1-git-send-email-moshe@nvidia.com> References: <1615828363-464-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b3019e9c-68b0-44af-22cb-08d8e7d59bd6 X-MS-TrafficTypeDiagnostic: MN2PR12MB3262: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1388; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gKA3hvTHHngIEHXAmYcTsRVDjNpfp5FcWFCRZEzhzjYGBq7gN2kvZsoqGmGiLFKXxCCTobhhNDWbIWGMVSnD3bQl7fJkFfBYyeuCdljwIwHjlTm+Pnwu/eFA7CgmzqZPBUo90rktP/SgI4UBS2nvxRDevZEERDWITbndsoEf5BxhBWlbRvYZVis2uyQ4FWFKnswMoMAjfrP29OIhK4hIPDUwwYPSxjfdpkeE3IyWIPd8nIq/G8DZ0uwUKIUuc/d06hV/d5ijDxXj1cxQwW5QZKK52xP+asYEiGbnZ0KnCwfak0hQk8t8grKORHKbEZWfzKPwAo96Ygz+ddtUxOircIi7OdbqmFMlXzBFVujze73YjrzYyZOXwCERiaok0e45fFLgA+kcMc2FISxBVC9X+HcYlLQbfGNyGxyTlfaUFb+yJ+OYBkY//VGS6Y2wZxxfcm6vQn7eW58U75iftMjDBHUB5Ue8XSJDPBh5ogSz5IYdZAmu5WieeQ+/wQoVUaOYgCcKCVqB2k+Td6Y+DJaZEMuWe4GrnmbWblRWDWNjtlE6ukApjhvca89FsJ5fk2E9upnLqptqE04XXBU8zBtySnQEAJfB8NRlh2d6Q6IfPOiFGUUDMrI8i25EK5U5CDDTywWfIqi154nacRSEDub5iSEo1pb1pARFnGEDFivYpys3BFCEmvX9E7rIdxu3QlJB X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(396003)(346002)(376002)(39860400002)(136003)(36840700001)(46966006)(2906002)(4326008)(478600001)(6666004)(36756003)(86362001)(186003)(426003)(107886003)(82310400003)(34020700004)(2616005)(356005)(83380400001)(7696005)(7636003)(47076005)(8936002)(5660300002)(70586007)(70206006)(36906005)(8676002)(336012)(316002)(36860700001)(110136005)(54906003)(82740400003)(26005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 17:13:10.0298 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b3019e9c-68b0-44af-22cb-08d8e7d59bd6 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3262 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladyslav Tarasiuk In case netlink get_module_eeprom_data_by_page() callback is not implemented by the driver, try to call old get_module_info() and get_module_eeprom() pair. Recalculate parameters to get_module_eeprom() offset and len using page number and their sizes. Return error if this can't be done. Signed-off-by: Vladyslav Tarasiuk --- net/ethtool/eeprom.c | 75 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/net/ethtool/eeprom.c b/net/ethtool/eeprom.c index e110336dc231..33ba9ecc36cb 100644 --- a/net/ethtool/eeprom.c +++ b/net/ethtool/eeprom.c @@ -25,6 +25,79 @@ struct eeprom_data_reply_data { #define EEPROM_DATA_REPDATA(__reply_base) \ container_of(__reply_base, struct eeprom_data_reply_data, base) +static int fallback_set_params(struct eeprom_data_req_info *request, + struct ethtool_modinfo *modinfo, + struct ethtool_eeprom *eeprom) +{ + u32 offset = request->offset; + u32 length = request->length; + + if (request->page) { + if (offset < 128 || offset + length > ETH_MODULE_EEPROM_PAGE_LEN) + return -EINVAL; + offset = request->page * 128 + offset; + } + + if (modinfo->type == ETH_MODULE_SFF_8079 && + request->i2c_address == 0x51) + offset += ETH_MODULE_EEPROM_PAGE_LEN; + + if (!length) + length = modinfo->eeprom_len; + + if (offset >= modinfo->eeprom_len) + return -EINVAL; + + if (modinfo->eeprom_len < offset + length) + length = modinfo->eeprom_len - offset; + + eeprom->cmd = ETHTOOL_GMODULEEEPROM; + eeprom->len = length; + eeprom->offset = offset; + + return 0; +} + +static int eeprom_data_fallback(struct eeprom_data_req_info *request, + struct eeprom_data_reply_data *reply, + struct genl_info *info) +{ + struct net_device *dev = reply->base.dev; + struct ethtool_modinfo modinfo = {0}; + struct ethtool_eeprom eeprom = {0}; + u8 *data; + int err; + + if ((!dev->ethtool_ops->get_module_info && + !dev->ethtool_ops->get_module_eeprom) || request->bank) { + return -EOPNOTSUPP; + } + modinfo.cmd = ETHTOOL_GMODULEINFO; + err = dev->ethtool_ops->get_module_info(dev, &modinfo); + if (err < 0) + return err; + + err = fallback_set_params(request, &modinfo, &eeprom); + if (err < 0) + return err; + + data = kmalloc(eeprom.len, GFP_KERNEL); + if (!data) + return -ENOMEM; + err = dev->ethtool_ops->get_module_eeprom(dev, &eeprom, data); + if (err < 0) + goto err_out; + + reply->data = data; + reply->length = eeprom.len; + + return 0; + +err_out: + kfree(data); + return err; +} + static int eeprom_data_prepare_data(const struct ethnl_req_info *req_base, struct ethnl_reply_data *reply_base, struct genl_info *info) @@ -36,7 +109,7 @@ static int eeprom_data_prepare_data(const struct ethnl_req_info *req_base, int ret; if (!dev->ethtool_ops->get_module_eeprom_data_by_page) - return -EOPNOTSUPP; + return eeprom_data_fallback(request, reply, info); page_data.offset = request->offset; page_data.length = request->length;