From patchwork Thu Mar 25 14:56:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 12164253 X-Patchwork-Delegate: kuba@kernel.org 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 9807BC433E3 for ; Thu, 25 Mar 2021 14:58:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74DAD61A10 for ; Thu, 25 Mar 2021 14:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231339AbhCYO5h (ORCPT ); Thu, 25 Mar 2021 10:57:37 -0400 Received: from mail-bn8nam12on2060.outbound.protection.outlook.com ([40.107.237.60]:3424 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230406AbhCYO5P (ORCPT ); Thu, 25 Mar 2021 10:57:15 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZL7viCQzSK7G4OFwjG+o3+3VC655c3GuN+C5M5WC9QtZYVPX+iw7R+v7tK4DHhblT252fR3PWnvgUCoO7AeebdVbI1glfVieuBiXZMMf2eSOldUQcSqyhEBaLi+4PeQN1GcIuZD+3pJN2H0iYxeLXBAs6Xxe5FkZLFKCGG9lcBnFws4X+XbkKfTLCAa5Y/KGyzJC8W34vbFFpTZKhmEz65+KnDJ/GGn8vSd68fUjjbPzpDSQSxhNtvPSlfDeRluVY2c/e5/w4RvxHrfSR3hGPSACM7Tk8VbVWzg3raO9/gUkpLBEJwGjI8f9DCLCTroFaUiju/YHHK5YrR5VBoaovQ== 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=LpJ48wTn7BYFG3GgIbOX4FjiTc06XuWBWb+wu3vpEx8=; b=TMEIPkGcIOJX+F8sNvv+VF2FQuS9Y0EjJiLO/BYTQhN8XZfcFMTgJdYRaNSNc6eucr43U/FfaaTSqyeoUeztyedPOn2tkH7IgEahE0iISW9ASFx53wCBCpDobMtMZRisjhq+dtIcKmkfFUOKVpqIg9Jood5J8F1niF9qh/WGGaLLipks/HwjKSWHtI1OhD7Nufo13prOYNj5xjEvMQubcquaYKGQEI7CfJLQKt908JJVeY6UabkTH+hYlEbIBll5NN8mC1ezGWuSec3vtb53aZj3XPHANFdRHQSo2seSX5Tn4A2ul66151m9M5GC0lCCaNrreLKA0RISiNMLyIqHww== 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=LpJ48wTn7BYFG3GgIbOX4FjiTc06XuWBWb+wu3vpEx8=; b=R6priYGeZg1zo6IsWq7v+cz7euwQgA8+g9oa2UI5E9xy/4bvnTrWdDW8SoWaRipTKanO09efg2gAjG5ikAIu+vTSAOJNP1EE4ZlUseV9G1f9MpZn4dRC9lDRH6gXnVmIj3dhntvl5vBAccuiY/gB5Vj8HHgqIPih2ps4lUa8yDNpxqB7vOhH09ZR0kQ5oA0cYpx8jD2pKz8t1yTi71PyKxxZQFwLx5sjcpGRTxF5YAhwJmLWhBWeXQty8xBPxPu6KIjzmEIasIYINjeebx3jewU9MGeflvFQkKMi2XZB7hl3NCZdBEVsO/IirZUox8/+2HS8XzUJLaeSe84bg/03rw== Received: from CO1PR15CA0100.namprd15.prod.outlook.com (2603:10b6:101:21::20) by DM5PR12MB1289.namprd12.prod.outlook.com (2603:10b6:3:79::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Thu, 25 Mar 2021 14:57:13 +0000 Received: from CO1NAM11FT043.eop-nam11.prod.protection.outlook.com (2603:10b6:101:21:cafe::bb) by CO1PR15CA0100.outlook.office365.com (2603:10b6:101:21::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Thu, 25 Mar 2021 14:57:13 +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 CO1NAM11FT043.mail.protection.outlook.com (10.13.174.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3955.18 via Frontend Transport; Thu, 25 Mar 2021 14:57:12 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 25 Mar 2021 14:57:12 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 25 Mar 2021 07:57:10 -0700 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 V5 net-next 1/5] ethtool: Allow network drivers to dump arbitrary EEPROM data Date: Thu, 25 Mar 2021 16:56:51 +0200 Message-ID: <1616684215-4701-2-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1616684215-4701-1-git-send-email-moshe@nvidia.com> References: <1616684215-4701-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 26097838-89dc-4b26-a2c9-08d8ef9e4601 X-MS-TrafficTypeDiagnostic: DM5PR12MB1289: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9Sa8W6bPOfE3kr/2bxJ2i+dwkPGB4Z4vcdAXjmMskY2fg0ceBeTq1kctGEF20+P562Mwqkp3J1WnZnjwWphbD670N2zJnQ5wbW0+L+Xy3RnbZCpjHT9Q95QkRzUn2HXMz6Sp44SgsKapYCJvorZ/4DGAKhKvwE5Boe1Bl2oNqAzpgwv0fwiJt1AyDMI5Q/nkvlURRUY5Pouk0jY2/MS1kmPaZYY9/8V24uGguzBB+1gxA8LucT2ZZO554rIt3NbLLHiGD/iQYBHZbT45MFq1nVgryHJS1BQajXYbB2OyBsnDu8xWEXMI1E6NmaLrCRvZc9h7VDlO9DmFdNY/g+qSRw5GzvbgyV9egqC4nhh1dwlrJgybP0iuj4IfLBMbU4xSpfQViREtjkg5/l3IBU/i28tKkw5DshNiSAXNCksCMHXUjxchWbopgtO5LtFY479Od0NrCJLlWeBXRrURjZDFyaD7osQFyZRFtgQAfFJK0gmp9Iwc31FWG5P+7YVrJq3HzdUzaIDjQ4zCTmukjJTTwB3pBT0DTmEIcWa358ktKqIT5o9SwkOhc/zauFLkRre3myzMH8BDgynJeuEKJSpklZbjMurrywWj11Va1SHwrloUj9floScUEKCK8TygoMjRhFKilktJZoXOcj8PXdc00A== 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)(39860400002)(136003)(376002)(346002)(46966006)(36840700001)(7696005)(83380400001)(107886003)(356005)(2906002)(82740400003)(6666004)(426003)(336012)(7636003)(2616005)(8676002)(4326008)(8936002)(26005)(36906005)(36860700001)(5660300002)(86362001)(30864003)(54906003)(478600001)(316002)(110136005)(36756003)(70206006)(70586007)(47076005)(82310400003)(186003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2021 14:57:12.9969 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 26097838-89dc-4b26-a2c9-08d8ef9e4601 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: CO1NAM11FT043.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1289 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Vladyslav Tarasiuk Define get_module_eeprom_by_page() ethtool callback and implement netlink infrastructure. get_module_eeprom_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 | 36 +++- include/linux/ethtool.h | 33 +++- include/uapi/linux/ethtool_netlink.h | 19 +++ net/ethtool/Makefile | 2 +- net/ethtool/eeprom.c | 170 +++++++++++++++++++ net/ethtool/netlink.c | 10 ++ net/ethtool/netlink.h | 2 + 7 files changed, 268 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..b6a21b9d1973 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -1280,6 +1280,38 @@ 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. +MODULE_EEPROM +=========== + +Fetch module EEPROM data dump. +This interface is designed to allow dumps of at most 1/2 page at once. This +means only dumps of 128 (or less) bytes are allowed, without crossing half page +boundary located at offset 128. For pages other than 0 only high 128 bytes are +accessible. + +Request contents: + + ======================================= ====== ========================== + ``ETHTOOL_A_MODULE_EEPROM_HEADER`` nested request header + ``ETHTOOL_A_MODULE_EEPROM_OFFSET`` u32 offset within a page + ``ETHTOOL_A_MODULE_EEPROM_LENGTH`` u32 amount of bytes to read + ``ETHTOOL_A_MODULE_EEPROM_PAGE`` u8 page number + ``ETHTOOL_A_MODULE_EEPROM_BANK`` u8 bank number + ``ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS`` u8 page I2C address + ======================================= ====== ========================== + +Kernel response contents: + + +---------------------------------------------+--------+---------------------+ + | ``ETHTOOL_A_MODULE_EEPROM_HEADER`` | nested | reply header | + +---------------------------------------------+--------+---------------------+ + | ``ETHTOOL_A_MODULE_EEPROM_DATA`` | nested | array of bytes from | + | | | module EEPROM | + +---------------------------------------------+--------+---------------------+ + +``ETHTOOL_A_MODULE_EEPROM_DATA`` has an attribute length equal to the amount of +bytes driver actually read. + Request translation =================== @@ -1357,8 +1389,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 3583f7fc075c..19a609a4b714 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); @@ -265,6 +266,31 @@ struct ethtool_pause_stats { u64 rx_pause_frames; }; +#define ETH_MODULE_EEPROM_PAGE_LEN 128 +#define ETH_MODULE_MAX_I2C_ADDRESS 0x7f + +/** + * 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_module_eeprom { + __u32 offset; + __u32 length; + __u8 page; + __u8 bank; + __u8 i2c_address; + __u8 *data; +}; + /** * struct ethtool_ops - optional netdev operations * @cap_link_lanes_supported: indicates if the driver supports lanes @@ -410,6 +436,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_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 +544,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_by_page)(struct net_device *dev, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack); }; int ethtool_check_ops(const struct ethtool_ops *ops); @@ -538,7 +570,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_netlink.h b/include/uapi/linux/ethtool_netlink.h index a286635ac9b8..c99dea5afbb2 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_MODULE_EEPROM_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_MODULE_EEPROM_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 */ + +enum { + ETHTOOL_A_MODULE_EEPROM_UNSPEC, + ETHTOOL_A_MODULE_EEPROM_HEADER, /* nest - _A_HEADER_* */ + + ETHTOOL_A_MODULE_EEPROM_OFFSET, /* u32 */ + ETHTOOL_A_MODULE_EEPROM_LENGTH, /* u32 */ + ETHTOOL_A_MODULE_EEPROM_PAGE, /* u8 */ + ETHTOOL_A_MODULE_EEPROM_BANK, /* u8 */ + ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS, /* u8 */ + ETHTOOL_A_MODULE_EEPROM_DATA, /* nested */ + + __ETHTOOL_A_MODULE_EEPROM_CNT, + ETHTOOL_A_MODULE_EEPROM_MAX = (__ETHTOOL_A_MODULE_EEPROM_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..10d5f6b34f2f --- /dev/null +++ b/net/ethtool/eeprom.c @@ -0,0 +1,170 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include "netlink.h" +#include "common.h" + +struct eeprom_req_info { + struct ethnl_req_info base; + u32 offset; + u32 length; + u8 page; + u8 bank; + u8 i2c_address; +}; + +struct eeprom_reply_data { + struct ethnl_reply_data base; + u32 length; + u8 *data; +}; + +#define MODULE_EEPROM_REQINFO(__req_base) \ + container_of(__req_base, struct eeprom_req_info, base) + +#define MODULE_EEPROM_REPDATA(__reply_base) \ + container_of(__reply_base, struct eeprom_reply_data, base) + +static int eeprom_prepare_data(const struct ethnl_req_info *req_base, + struct ethnl_reply_data *reply_base, + struct genl_info *info) +{ + struct eeprom_reply_data *reply = MODULE_EEPROM_REPDATA(reply_base); + struct eeprom_req_info *request = MODULE_EEPROM_REQINFO(req_base); + struct ethtool_module_eeprom page_data = {0}; + struct net_device *dev = reply_base->dev; + int ret; + + if (!dev->ethtool_ops->get_module_eeprom_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_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_parse_request(struct ethnl_req_info *req_info, struct nlattr **tb, + struct netlink_ext_ack *extack) +{ + struct eeprom_req_info *request = MODULE_EEPROM_REQINFO(req_info); + + if (!tb[ETHTOOL_A_MODULE_EEPROM_OFFSET] || + !tb[ETHTOOL_A_MODULE_EEPROM_LENGTH] || + !tb[ETHTOOL_A_MODULE_EEPROM_PAGE] || + !tb[ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS]) + return -EINVAL; + + request->i2c_address = nla_get_u8(tb[ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS]); + request->offset = nla_get_u32(tb[ETHTOOL_A_MODULE_EEPROM_OFFSET]); + request->length = nla_get_u32(tb[ETHTOOL_A_MODULE_EEPROM_LENGTH]); + + if (!request->length) + return -EINVAL; + + /* The following set of conditions limit the API to only dump 1/2 + * EEPROM page without crossing low page boundary located at offset 128. + * This means user may only request dumps of length limited to 128 from + * either low 128 bytes or high 128 bytes. + * For pages higher than 0 only high 128 bytes are accessible. + */ + request->page = nla_get_u8(tb[ETHTOOL_A_MODULE_EEPROM_PAGE]); + if (request->page && request->offset < ETH_MODULE_EEPROM_PAGE_LEN) { + NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_PAGE], + "reading from lower half page is allowed for page 0 only"); + return -EINVAL; + } + + if (request->offset < ETH_MODULE_EEPROM_PAGE_LEN && + request->offset + request->length > ETH_MODULE_EEPROM_PAGE_LEN) { + NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_LENGTH], + "reading cross half page boundary is illegal"); + return -EINVAL; + } else if (request->offset >= ETH_MODULE_EEPROM_PAGE_LEN * 2) { + NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_OFFSET], + "offset is out of bounds"); + return -EINVAL; + } else if (request->offset + request->length > ETH_MODULE_EEPROM_PAGE_LEN * 2) { + NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_LENGTH], + "reading cross page boundary is illegal"); + return -EINVAL; + } + if (tb[ETHTOOL_A_MODULE_EEPROM_BANK]) + request->bank = nla_get_u8(tb[ETHTOOL_A_MODULE_EEPROM_BANK]); + + return 0; +} + +static int eeprom_reply_size(const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + const struct eeprom_req_info *request = MODULE_EEPROM_REQINFO(req_base); + + return nla_total_size(sizeof(u8) * request->length); /* _EEPROM_DATA */ +} + +static int eeprom_fill_reply(struct sk_buff *skb, + const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + struct eeprom_reply_data *reply = MODULE_EEPROM_REPDATA(reply_base); + + return nla_put(skb, ETHTOOL_A_MODULE_EEPROM_DATA, reply->length, reply->data); +} + +static void eeprom_cleanup_data(struct ethnl_reply_data *reply_base) +{ + struct eeprom_reply_data *reply = MODULE_EEPROM_REPDATA(reply_base); + + kfree(reply->data); +} + +const struct ethnl_request_ops ethnl_module_eeprom_request_ops = { + .request_cmd = ETHTOOL_MSG_MODULE_EEPROM_GET, + .reply_cmd = ETHTOOL_MSG_MODULE_EEPROM_GET_REPLY, + .hdr_attr = ETHTOOL_A_MODULE_EEPROM_HEADER, + .req_info_size = sizeof(struct eeprom_req_info), + .reply_data_size = sizeof(struct eeprom_reply_data), + + .parse_request = eeprom_parse_request, + .prepare_data = eeprom_prepare_data, + .reply_size = eeprom_reply_size, + .fill_reply = eeprom_fill_reply, + .cleanup_data = eeprom_cleanup_data, +}; + +const struct nla_policy ethnl_module_eeprom_get_policy[] = { + [ETHTOOL_A_MODULE_EEPROM_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy), + [ETHTOOL_A_MODULE_EEPROM_OFFSET] = { .type = NLA_U32 }, + [ETHTOOL_A_MODULE_EEPROM_LENGTH] = { .type = NLA_U32 }, + [ETHTOOL_A_MODULE_EEPROM_PAGE] = { .type = NLA_U8 }, + [ETHTOOL_A_MODULE_EEPROM_BANK] = { .type = NLA_U8 }, + [ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS] = + NLA_POLICY_RANGE(NLA_U8, 0, ETH_MODULE_MAX_I2C_ADDRESS), +}; + diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 50d3c8896f91..52d1ffb1bca2 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_MODULE_EEPROM_GET] = ðnl_module_eeprom_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_MODULE_EEPROM_GET, + .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + .policy = ethnl_module_eeprom_get_policy, + .maxattr = ARRAY_SIZE(ethnl_module_eeprom_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..71cbd9df8229 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_module_eeprom_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_module_eeprom_get_policy[ETHTOOL_A_MODULE_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 Thu Mar 25 14:56:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 12164249 X-Patchwork-Delegate: kuba@kernel.org 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 A5EF1C433E5 for ; Thu, 25 Mar 2021 14:58:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F08261A2B for ; Thu, 25 Mar 2021 14:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231363AbhCYO5i (ORCPT ); Thu, 25 Mar 2021 10:57:38 -0400 Received: from mail-co1nam11on2069.outbound.protection.outlook.com ([40.107.220.69]:22054 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230182AbhCYO5S (ORCPT ); Thu, 25 Mar 2021 10:57:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WAold8kplL5/n9rBoWPtmE+FskRmHgwQ8gBN6OIX1RPIobnlEiTtOHmhxSdfhN5XCjQt+OsVlz53ciRoqhDUV2dACnsL1SbmM7A/IG7AQvmYLQ8TFHBtbNZnwoHMjWB2X+OtXOS8X0nE3njLbgjiarkKogGlP8sL68m9NTCk2oY+SOa34b7O0+rkM9apAS49QYmWPcHvxkX1LjwoRqZ0tl0j/BgC7FVa7E9Eyt3H8R73I+IxjQpqP8mFa+G7xpnefNsl8VHmr8EnAlUP0wx28xwOdQr8jNb4WYWZI/bNrCj6y4c1tj53wuIsNBqoQHUShF4c5iGTBe9GbwMG2OUEaA== 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=XjJrGI0gx7yLAatxbRqvEgXBS5lBriQHj5Zp2JAXHPE=; b=FNgY/8wBM6LAnXJJxRTtIVgIxIdIVa0P7dbYM105x/HEaljnK2Tb/HcG12FfGMe7yCWzbSqa4R+tDl0aYZ4RJJmRJMCgmwfFvfUfgeE8ZNzDywG5vNlW1zW5K23XozS8HiKbX+CojqAg3CrERC+SGuabNcB3xVE71DfuBmIIB/udlYM1emQOc3GISvtv+eJbd4NeyKD/bZiKAEKaG4FAgOzgTpjepKArUMkTS0Chb0zE/e3tlXlWleod3yTcwmdhBFeepEJIaa6PxXasteS+Fdwblrax0r8uwGG8Lkjg6f2YqA0kdUlLDJyb53S4zm1bUmegxeBhYlGPweET0FBmLQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=davemloft.net 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=XjJrGI0gx7yLAatxbRqvEgXBS5lBriQHj5Zp2JAXHPE=; b=ryF6oYjtw92PNdDkpa37W8m8YinXPsPlrftwwzM+JSmKiKwAPlbFeVdqa7EQHtNIj4UripDx8sqOAKrH92T8IWtiABtK8e4uMDL79FQjOznThiq7mcD7YknFUbtNhvrAOMNWGcXc5NWPmo0ToGxlCb3JeMO83nrRy1nO905A62svPKjrCn1G6X1TRMTwCTwpCVshvdf26UKXRa1AraryJtUDkKmiUu/SY+GSrkvZ6Xvr6wT7ArWoTrmI0hE1KFCb0IXze4IRdIxjZG562hncNJSBColW5AkM7yvmUSsWb/KI3Uwen9j5KDO2m/sj+N+b1MTJ2MXXtrtJeiny5OkDPA== Received: from BN0PR04CA0136.namprd04.prod.outlook.com (2603:10b6:408:ed::21) by BN6PR12MB1700.namprd12.prod.outlook.com (2603:10b6:404:108::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Thu, 25 Mar 2021 14:57:16 +0000 Received: from BN8NAM11FT016.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ed:cafe::50) by BN0PR04CA0136.outlook.office365.com (2603:10b6:408:ed::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Thu, 25 Mar 2021 14:57:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; davemloft.net; dkim=none (message not signed) header.d=none;davemloft.net; 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 BN8NAM11FT016.mail.protection.outlook.com (10.13.176.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3955.18 via Frontend Transport; Thu, 25 Mar 2021 14:57:16 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 25 Mar 2021 14:57:15 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 25 Mar 2021 14:57:14 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 25 Mar 2021 07:57:12 -0700 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 V5 net-next 2/5] net/mlx5: Refactor module EEPROM query Date: Thu, 25 Mar 2021 16:56:52 +0200 Message-ID: <1616684215-4701-3-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1616684215-4701-1-git-send-email-moshe@nvidia.com> References: <1616684215-4701-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 216e5bc3-8747-4134-ddec-08d8ef9e47e2 X-MS-TrafficTypeDiagnostic: BN6PR12MB1700: 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: n1bbRNbZNqhzknA5W1dsb4vFuEcH6xkgxxXBlsZbp4jZhnMQZBdVb0d5kvEs2GBG+nM2NjT1nkUEmyGnOKKnSgQ1Tj8OrvWbaZQQn99a8tGyU0F9LtK2x5Sa3MgPaDf9ac3MraGukrxMn7Y1lvG1nfTp6cma4UDHdAoYoT3pH1KY9vTXCKyjAH8cJ7IjPDK8GSLwBh7HO5DgsZJNvJSDnFrqsttSXh0W+RKb2G9tumWEjWRXcvJOD86FSzAmfDnsw300Pusz6Fw5PY7VspSzqLDcHwm61qKisL6m8JqsZsHJbt83K08eELKC8MRivTBF4/LeY/uqIcMGNyeA/J40X0GvrZfPD3VVDA+eYiN/sp3B3A5SaXGPeRfK2hmmAFM+QKjdZ94wBXWmWJEtfNjo1LFcp5hSGixYmQvKN52oHhzTq3LPpIcq9T0vxoiWmJIEdyjTGNQurdlxMHmDeNXF4pJYnNpcxB2XHhdBciJ+uoz7bqRQGfLhf+pZL3YCxXCMznOVNyc0RM3ITmhQzD4l9HnjB69IC73YI2gN6VSWhPHC3Ysh/5YTIzzV5yxQD2zAAAEG+v9aNiLEMYhQiH+gGyihILKnRexzimGsV1t8QGqM/fCEBdBYHBWX74XQVpgerpDXUqYHz2tb/bFJbqYi9w== 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)(376002)(396003)(39860400002)(36840700001)(46966006)(2906002)(107886003)(336012)(70206006)(7636003)(70586007)(4326008)(426003)(36860700001)(82740400003)(5660300002)(26005)(6666004)(2616005)(356005)(186003)(7696005)(54906003)(47076005)(110136005)(86362001)(8676002)(316002)(36756003)(478600001)(82310400003)(8936002)(36906005)(83380400001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2021 14:57:16.1277 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 216e5bc3-8747-4134-ddec-08d8ef9e47e2 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: BN8NAM11FT016.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1700 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 Thu Mar 25 14:56:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 12164255 X-Patchwork-Delegate: kuba@kernel.org 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 BF608C433E6 for ; Thu, 25 Mar 2021 14:58:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A653C61A17 for ; Thu, 25 Mar 2021 14:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231381AbhCYO5k (ORCPT ); Thu, 25 Mar 2021 10:57:40 -0400 Received: from mail-mw2nam10on2046.outbound.protection.outlook.com ([40.107.94.46]:40879 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230230AbhCYO5V (ORCPT ); Thu, 25 Mar 2021 10:57:21 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hPCDJpY2+28LdBXfN0Y4jjngerZ95TgXwufnVTJqhXAXLg+qIAyvW08gJjZ1hv5xHnoNZRv/mrwo8ovAiEvdNCpGc/aSdMadnf/8su7AWk0/nyvDFqxXlFV9ngXNr43zIm39s+pKZ7Y2xyyZ3joJDHZ+Gg/6h/DxXiDLAqnkuHY7uBJ83OOjNewFW4lZIGOsCufij/beCsrV0ekcEWFCUxZtp6ha/FoeuNw0AFjFCtIoAeqBpU546yOxEvYir+1KP3TXJecaAKIBpaZMaFd+LW/qqDCdbGgkG3YD/a4kiUXwn/avlrg6fRSBB8IcXMyqnBvlwK53D2oCs9rygKCXOw== 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=iYHmzveQFqCEHdEoUsnWodVAEPVuUJ5U5VML3uDlBfA=; b=fPvg4223SktArZtdDrGVfWUtYa9Q9Q+lddSGUzZiXW71CkDoAnWxuTzP2zDaiI8VrsGhkqMT/gdUfB756moqOcdtHr4UdvNfELDUJUITe8O8NwTOIom9Frb67Ut5fQhWoBDbbATwY4d5xf0EbxO6H5+NzjDKJXhWBnyzVYcLOXDcvmfq5lFm0rR3sndcmOivGeS333QqGNBlYUKcRRjVOT9VP3UWdT6q2oMruTxCu+UehLwCV4TLHM0UZVRa4bQB+yfa9XdTdeTsob4iCeotvhYa7daT7VTYVJ3DtSswYIxfhIKD59+pOf2gKuMDCkczuARSaAk4rNHp0Qfznl83Gg== 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=iYHmzveQFqCEHdEoUsnWodVAEPVuUJ5U5VML3uDlBfA=; b=XxaEsnRBcj/Jj1NlPUh4Cw/jF3VgiB3q0MRo5OZM3gIX632+szX8qoiASfgH6Un5Qo97bBXHevtkiKSMLl8px0LI4XPb03liPZPTqt9rMYoacxyKJzMMiZRnMLJyMA9Nrs3I1bKAOBln4dpsl336V+QGInvd35CceEQpGqWSMO2RJiWfuaK+j5uD7vxmgHBXhIFe9z3hLrFXzLLJp/E0jb7OJkKqHFE2KWiwxG42XfpIL8b7uzERm6anOdI9OafmezlXrS/iuY7FbG6/zGKkemNKjDR20s4tPgCqrWy8uqk2YDC7M5WDOfHZRnI1LdUCpTR1jhOjMmhR8Cp1fC8PNg== Received: from BN8PR04CA0063.namprd04.prod.outlook.com (2603:10b6:408:d4::37) by CH2PR12MB3991.namprd12.prod.outlook.com (2603:10b6:610:2f::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Thu, 25 Mar 2021 14:57:18 +0000 Received: from BN8NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:408:d4:cafe::e0) by BN8PR04CA0063.outlook.office365.com (2603:10b6:408:d4::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Thu, 25 Mar 2021 14:57:18 +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 BN8NAM11FT048.mail.protection.outlook.com (10.13.177.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3955.18 via Frontend Transport; Thu, 25 Mar 2021 14:57:18 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 25 Mar 2021 14:57:18 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 25 Mar 2021 07:57:15 -0700 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 V5 net-next 3/5] net/mlx5: Implement get_module_eeprom_by_page() Date: Thu, 25 Mar 2021 16:56:53 +0200 Message-ID: <1616684215-4701-4-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1616684215-4701-1-git-send-email-moshe@nvidia.com> References: <1616684215-4701-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bb1f8a53-243f-4629-9997-08d8ef9e495b X-MS-TrafficTypeDiagnostic: CH2PR12MB3991: 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: mP0PFe+6RauRSEe1cy3JKaUNgnOKaW7GrWMZL7pzzT00x+YPJvb5B7lL2bNgQe4UmIArEupUjL4tfVDZ0ZYV+i4w0bcip95LtME0YBZJ+omr2KROJVsJE56XruBu+i9ZOXMhd8TOf0miw0UaUc2ZKqXVTAKrnu0o6j2bySbDx1fS/PxNEuNWgksbrFX01r7My/3EFCff5hvIPn4rx6jFCB0nUQtwMk5u7TO8sRpGrIzYmXyKxHe2GXQelemlhjP5SN5fDVHEK1Gd7nPDlaBYyLHC9YRxSSL+2iaik1k5R9GzRRNhKjXE3U/3ge7WTR1HGPrNciV7rhEqmiXCPKxr6oM39VymtX/LEvZoX5hpWopRwAcXMaP5BGUHb4/p0z32l+7Ft7yzn/NLdrhINYG6IgXvfeEKe4JL6gfnj83TG1ugTK1k3TIslUMBG+oHgiCYVdxAfR0iz8M8oJdtHWPZEN2Aq1LcxgySwBTCOhLycCCRtTIlSoqTfqKf2IyBB/AbpHL0S201aFtN/iDHFOBvMuf3sfWbIjXiEH9bmIcMC1dg8PmISfRP8o3pz+Ru6gccNQ5MTQ67jRlhRc+jUyzgGWwSfMGN9aIDIhjXkhMeRFa3GBlWbA5pYDqbf+YxdKcZSVSCjrxMmqWDr282rG8wrEUR8K8A9sxh4Hv9D47nM2Y= 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)(396003)(136003)(346002)(376002)(39860400002)(36840700001)(46966006)(70586007)(70206006)(8676002)(4326008)(6666004)(8936002)(107886003)(86362001)(82310400003)(426003)(336012)(5660300002)(36756003)(2616005)(7636003)(7696005)(26005)(36860700001)(186003)(83380400001)(82740400003)(478600001)(2906002)(110136005)(54906003)(47076005)(36906005)(316002)(356005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2021 14:57:18.5957 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bb1f8a53-243f-4629-9997-08d8ef9e495b 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: BN8NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3991 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Vladyslav Tarasiuk Implement ethtool_ops::get_module_eeprom_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..7f413f7bd1d3 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_by_page(struct net_device *netdev, + const struct ethtool_module_eeprom *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_by_page(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_by_page 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_by_page = mlx5e_get_module_eeprom_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..114214728e32 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_by_page(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_by_page); + 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..58d56adb9842 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_by_page(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 Thu Mar 25 14:56:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 12164251 X-Patchwork-Delegate: kuba@kernel.org 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 CC903C433E4 for ; Thu, 25 Mar 2021 14:58:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B8D8461A10 for ; Thu, 25 Mar 2021 14:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231393AbhCYO5m (ORCPT ); Thu, 25 Mar 2021 10:57:42 -0400 Received: from mail-co1nam11on2081.outbound.protection.outlook.com ([40.107.220.81]:10144 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230497AbhCYO5X (ORCPT ); Thu, 25 Mar 2021 10:57:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tb50YIHntt4CbW5IbRNaf1B/at3nyhurBBt5YprUv3qOZqopNEqwQNh9a3WbB0fYnOY2llMigrXFd17uTfgSdLhIRnmALh9I1ztbxmUqdJrgP/1eHDCSayqsTuAevaZCUf4h8fM+Urk/EY5k8arBAXx4nPiAny0fd964WXk9J6O+4SqhXqaWpR6C3r5ruL9Yf6eu/Torl/jnBWALd3JplUVI59McOWdlibntSME9oDMg7czAkHxKQma1riY6PHT/7ElNPT8efSagiTTpIlpV7kgUPwP1ndu+6ggOxQ2w74fy5X8fn9MKB/NhTnfNf1by4jpUAhVywoZWCdreruhUyA== 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=2nOLsR8yFycqExWNW7BcJ3CNDyRr/eoDLJdsqnukwYo=; b=lCYVlKFadMSvgNX4UyztbzWcrnzS8u9qXCzMDdfffxWuBKY7up0DDP73YHmfUklc0jKfYWwe6oj5vxRtvvGW9nO0qHMrH4d1PmZaGxkL8FoagUHitRATWA8PX0shAYxQYNp1reJr1EPkW6UE/6575RE7g4+QxJyk/5XEwOFwEHp162FrOjI72szQvN4dqN6urcmdVICW7Ywg7Mtx7OQ6AWnjPC9V6E/YXeLe4TRHVP40vAyXnzyiERZMDpQK7IB/v4RE1UX+6/SELVRveseuRbP3mXbJTG7HaQxg+tgAWmE8DdBOISusf7SShQX2gBayJTHWAsog5Qoh8JdAlZADiA== 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=2nOLsR8yFycqExWNW7BcJ3CNDyRr/eoDLJdsqnukwYo=; b=AeZmPPpNkGkAw13UnNWenzSeh6uLB/+xGJ+f0DhqnUhOLAmWSbGkRtaD7Ckm+1FKzTPMNGUrLfSLsfrld5jSqqza92iEW2uhr+WCSAthE2IdmG4QJJwXEUSCRf3ufda9YXa4C3B44zKKyd0m2CGCwM60aAvSabhCjc5PmvIa0UHXv6/hZflp7H2cRjzOrfpg9SgMkgIqtW58Lb/6plKmodJDgD4ni6Rz3VYQ3zkiLd/jGieU0Zq64rCUyoGEzTYiEzbbhgc9DogKbHZAvi9IVohuTW4JuxXqgLKaoVDVF+q1/kEayLa7rS/KStliThZ6U157LVdyXIuMIA0X/DkOjQ== Received: from MWHPR22CA0035.namprd22.prod.outlook.com (2603:10b6:300:69::21) by BN8PR12MB3041.namprd12.prod.outlook.com (2603:10b6:408:46::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Thu, 25 Mar 2021 14:57:22 +0000 Received: from CO1NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:300:69:cafe::ec) by MWHPR22CA0035.outlook.office365.com (2603:10b6:300:69::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.26 via Frontend Transport; Thu, 25 Mar 2021 14:57:21 +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 CO1NAM11FT008.mail.protection.outlook.com (10.13.175.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3955.18 via Frontend Transport; Thu, 25 Mar 2021 14:57:21 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 25 Mar 2021 14:57:20 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 25 Mar 2021 07:57:18 -0700 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 V5 net-next 4/5] net/mlx5: Add support for DSFP module EEPROM dumps Date: Thu, 25 Mar 2021 16:56:54 +0200 Message-ID: <1616684215-4701-5-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1616684215-4701-1-git-send-email-moshe@nvidia.com> References: <1616684215-4701-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 590be90e-e8d9-4e42-cdf1-08d8ef9e4ad1 X-MS-TrafficTypeDiagnostic: BN8PR12MB3041: 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: lDK/kGRoQzzNprnLYjCunrajNeMOv67XoW+hSmZCVJHzVhFmMunLj0wHBoX4+MG5MDxgQlqicQq8Yd4Hmucg/59npMExjFOLL87PeY6Jl8vtnnN5evT1cSqeuiNiJjXgGkeO28pnAK+GsV/GHE7wC+I28bQt40pCTOrp1dBImnT24KFxhHUNCylakKX8fSnqZyR6Gzhv08niab2FZVxzcr4bNFUJpmrvLAw1TzmHWXPZOTK6FpLGNc8XIOwXXwo36DyD6inUCNtyvqTdwaROEgI4CfvQIKF0JppmW8Bpf6j3I+4B0n9Wf2FureVLzoJFl6p+sL5HiiqeoL5rzpu9V69b26d+LNXgpVmSbr7XLTjzzW1yOvEpLa782K3NW33PzTiNANMXtnRkkSKG1KC6V2fNexo1ORjpIy/hckTK3Fb4p/E+zbI3rOHskoNrW5aYnwXNensfgty2RdRYCjZlxHHWDHKyuS9pItiQ7aLtAazyAJO9nr1Qmcqd4olKGqD2dqXwFf7rR7lyBDcLI0deJ3/K+A/7WPHG9ndX9skY07BVlQa4KlDN33DS6n3USE1//mQ6yiDd9baiJFdzmk4PzCS/5z/mBZxWMp7FKlVLa50dAOg+V/P/68mXsv60oEwktQrJDbEsEDuZef1bRLwjEN6MAYm6G6S7d90xonceCEc= 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)(346002)(136003)(396003)(376002)(39860400002)(46966006)(36840700001)(8676002)(70206006)(6666004)(4326008)(86362001)(8936002)(82310400003)(107886003)(426003)(70586007)(5660300002)(36756003)(336012)(2616005)(478600001)(36860700001)(26005)(36906005)(110136005)(186003)(356005)(83380400001)(2906002)(82740400003)(7696005)(47076005)(7636003)(316002)(54906003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2021 14:57:21.0940 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 590be90e-e8d9-4e42-cdf1-08d8ef9e4ad1 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: CO1NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3041 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 114214728e32..5008d6d30899 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_by_page(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 58d56adb9842..77ea4f9c5265 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 Thu Mar 25 14:56:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 12164257 X-Patchwork-Delegate: kuba@kernel.org 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 E6C90C433E8 for ; Thu, 25 Mar 2021 14:58:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA88561A3E for ; Thu, 25 Mar 2021 14:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229574AbhCYO5m (ORCPT ); Thu, 25 Mar 2021 10:57:42 -0400 Received: from mail-mw2nam10on2078.outbound.protection.outlook.com ([40.107.94.78]:32225 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230525AbhCYO50 (ORCPT ); Thu, 25 Mar 2021 10:57:26 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AHXqdTisroVHmuZ2u9iVbDo2FKIy+SWssUz65BUZgSjLvIA/yv0j5L6g+aeRw3ch1x2Hml8n0BTMZVhpDjoFEuvlW8uMXxTSwlGC/1adwhI7sj7B7KFIG6ZyAM+x8b5mcFceenur4wetTCH4030ynYzJ28JiUhVv0MvK9kmymoJhM3FuBkaOyPbzut/+7iQNwaOl7GDIJLp9j4lfAImyVXvysYdBR+KLFMDCA1Qjv4Qq05qCNQQDV9ALJ4MwhfApJBrMxzZWugj0QcN52h3zil7c7sOLe1XXHm84xchRtjT877Xru9ZLsXDjQ2C2HPDa90ENsB28C704ujQdCyHb7w== 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=sj54hgh5dJjkXB5IthWn4MrJ0cV0c0xOqIr7JyUhJow=; b=hS1bXYiIWbnYMRTqQq6i6hyLlCJYf4Px/PY/kXdWCBhGwZ6h20zp0zlGtyE4054XnD1hdNc4RleAqiNMdiFNc76vyaglA/EErW3RTT3pAVbXoxHY4eYVaEKbrLZkTX4SuuOZTYdOs2sV6A82v8Nk317DlrcJq/vF1ALwxyXTjw2tUWHe02rp0ac1n+rYve9zf+kXTT44HH2/ERqtbWgucimE7O6B3itmi+gAL1OR/UWu+ggExqGcaq3wtoQ+XjxxJbgjphTvwNNWv2t3I8bnwvlTBb7Pw/nkngL/cWfipUSIP5KV2Fck+qpeDb3DgvQ4UTpH1P+eD1EME2glu3/gZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=davemloft.net 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=sj54hgh5dJjkXB5IthWn4MrJ0cV0c0xOqIr7JyUhJow=; b=oOUnMv+fao/YLHsRbeQryKkm1jFvoBTSfU6/Y7ez8Qssfn2GQc/l/Y2fYOFXf93DiiCdi/s3Yoiv4dOs24ClP2akUUqRdD1GlvSaL4bh/fUQD7F4DxPioaNzI8UgeU/o+fv2rcxSBxCQ7j7anfZAaG6/J6bjG4mN1nWKGCszHQKBhpvHWbUUE3avfIco15BGacYce25p49hXVA9wGduLdAUHoDdCn/6LM3txYDGNxxN7SQGgIthEwlcFt8L3yGFu1+XtgYiXvP085Evua8SUMroOduV9EZjxJ7HFT2pwGbv9Y5FGv71L/W2VNs5OyqJSA017hbmKl1KIvPM3zdTipw== Received: from MWHPR12CA0061.namprd12.prod.outlook.com (2603:10b6:300:103::23) by DM6PR12MB2889.namprd12.prod.outlook.com (2603:10b6:5:18a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24; Thu, 25 Mar 2021 14:57:24 +0000 Received: from CO1NAM11FT030.eop-nam11.prod.protection.outlook.com (2603:10b6:300:103:cafe::ec) by MWHPR12CA0061.outlook.office365.com (2603:10b6:300:103::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29 via Frontend Transport; Thu, 25 Mar 2021 14:57:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; davemloft.net; dkim=none (message not signed) header.d=none;davemloft.net; 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 CO1NAM11FT030.mail.protection.outlook.com (10.13.174.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3955.18 via Frontend Transport; Thu, 25 Mar 2021 14:57:24 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 25 Mar 2021 14:57:23 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 25 Mar 2021 14:57:23 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 25 Mar 2021 07:57:20 -0700 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 V5 net-next 5/5] ethtool: Add fallback to get_module_eeprom from netlink command Date: Thu, 25 Mar 2021 16:56:55 +0200 Message-ID: <1616684215-4701-6-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1616684215-4701-1-git-send-email-moshe@nvidia.com> References: <1616684215-4701-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 08e57918-6241-470a-72d3-08d8ef9e4c99 X-MS-TrafficTypeDiagnostic: DM6PR12MB2889: 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: kZob/1uEo6tpsuLfSWbreTsMk1DRXnrwfVzM1Xm0h8+MdBwq9CXss3mNcFN2D+eGTeNXNllpd0DcnnEGzrt4sk33mYIfnIipAanNrbJALK6V6vFfvYw66CEV+x1hB9yNgvibueP5c6fFnY9UuziDOw807EvuWV6jCs2G6n4QHvjMSYkH0ELlP8/Mjf7NtxmNqEXIciXXIk0mHPtUbiZNYvm8X108aL5dnkUh8idjpQJLmWkgw6dHJXjvrvcmjBYJ2WXhF5Qh0O/rCjJEHkxbmU1xEtUjjUozcn/K9W1R4tpX9nPoZZbgG6ONqfubC89EO1T7N9yzeVes1s5LxK45Qkrqcdv0dsTjfotFHgvcP7klBzkU/VfMwlCGum7Z/yF5LAqe6d/oHaC5pFLc9eZCx6wbMU62e2XzBl+v35FQ84VQVbiTS6ZnR4yJv+RrPF/riDQTZl+TTJ0fnWIk8n8tSSCZVOrwkHL+wroy1fgC+HHatQmeAVBy6sjuWzdbCMoYkXfED9dzck2gFfHM4n7h2361//8NF00bQvnQUZvDqgymNRro9ffct7dzyU1EVoJoF192YKh/4GdZmBNvF38iw3ApLcRRga2OwtCtsEEk9y9s9uN1aahZaKuADYTUVvk1Wofq7/hwc+KOd6iamtxOkoqKbkOXTY7huWHMwfPX924= 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)(136003)(39860400002)(346002)(376002)(396003)(36840700001)(46966006)(8936002)(110136005)(426003)(2616005)(478600001)(356005)(82310400003)(70586007)(70206006)(7696005)(186003)(2906002)(4326008)(36756003)(336012)(36906005)(8676002)(82740400003)(107886003)(83380400001)(316002)(86362001)(6666004)(47076005)(36860700001)(5660300002)(54906003)(26005)(7636003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2021 14:57:24.0771 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 08e57918-6241-470a-72d3-08d8ef9e4c99 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: CO1NAM11FT030.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2889 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Vladyslav Tarasiuk In case netlink get_module_eeprom_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 | 66 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/net/ethtool/eeprom.c b/net/ethtool/eeprom.c index 10d5f6b34f2f..9f773b778bbe 100644 --- a/net/ethtool/eeprom.c +++ b/net/ethtool/eeprom.c @@ -25,6 +25,70 @@ struct eeprom_reply_data { #define MODULE_EEPROM_REPDATA(__reply_base) \ container_of(__reply_base, struct eeprom_reply_data, base) +static int fallback_set_params(struct eeprom_req_info *request, + struct ethtool_modinfo *modinfo, + struct ethtool_eeprom *eeprom) +{ + u32 offset = request->offset; + u32 length = request->length; + + if (request->page) + offset = request->page * ETH_MODULE_EEPROM_PAGE_LEN + offset; + + if (modinfo->type == ETH_MODULE_SFF_8079 && + request->i2c_address == 0x51) + offset += ETH_MODULE_EEPROM_PAGE_LEN; + + if (offset >= modinfo->eeprom_len) + return -EINVAL; + + eeprom->cmd = ETHTOOL_GMODULEEEPROM; + eeprom->len = length; + eeprom->offset = offset; + + return 0; +} + +static int eeprom_fallback(struct eeprom_req_info *request, + struct eeprom_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_prepare_data(const struct ethnl_req_info *req_base, struct ethnl_reply_data *reply_base, struct genl_info *info) @@ -36,7 +100,7 @@ static int eeprom_prepare_data(const struct ethnl_req_info *req_base, int ret; if (!dev->ethtool_ops->get_module_eeprom_by_page) - return -EOPNOTSUPP; + return eeprom_fallback(request, reply, info); page_data.offset = request->offset; page_data.length = request->length;