From patchwork Fri Apr 9 08:06:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 12193261 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=-18.8 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, URIBL_BLOCKED,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 E2171C433ED for ; Fri, 9 Apr 2021 08:07:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3749611C9 for ; Fri, 9 Apr 2021 08:07:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232051AbhDIIHP (ORCPT ); Fri, 9 Apr 2021 04:07:15 -0400 Received: from mail-mw2nam12on2049.outbound.protection.outlook.com ([40.107.244.49]:60385 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229621AbhDIIHO (ORCPT ); Fri, 9 Apr 2021 04:07:14 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kkb6GN7k+rbzHr5/TCdcIrm9qrj4TgRulTgsiIwCqzA32pQwuocCwmfG0ANIrTat/C0wmyEcttILCCnVTzMEqVpsiVoSBTDsDoRooTjMw1XlAQa2DCp0R6wFfFK+qvXgQrwL6KGDL2yTD4PNJmTiyxBDvmmvrkTEz4VxuWScDfh14xY/FTP82Tmmn63UjAihfHgZOQSRxejr9ici9jRezaerj6LtjWyk+QsDG8nc8XNxhTEq/VloVMs36W6bRNE13mBi2Z0+Qy1pzVXaRMs7yFztigwoV3l7CYWGkDT5IxIQpeq+SDf+ZbLXdAuyM2iFnnnqfDuwdvgqO6pXwCsdvg== 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=YeKwMJ96Ab7FiZx1ujYdjEFK0q5tfayD8J0ZC+Cs6PA=; b=Lr1rqhDEIRp0gEiIyUk0onc4zpPNrznSjMdOPm+Xr62TpVkjJxh1X5wkVQeYzjqtFszy1dtndqiFaAd/7OiJJL4HKaS++FYqU/nicRnaBd9tbqdSrwRz+f3TkVmOvVLLYcIymuRd691s1PSYkyAkgeCKLZMj98TmmJeSwWD0noOD2T4+ZQXLMbpy5I9e8yJ9ZKfCCbsq7BpFmqSWSHM9vO2W7wbRkqVlrTAG4HsUDbk6qvfkrc03PBwGSmEiOdDNkTD3JwFuYjXlFkMaG9fIa0OlTqkJSecJowctAau5gxzugkOCyKqJmh7VPNZlxFcCWhOTbtJ/1uDbfyvYt2kgrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=gmail.com 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=YeKwMJ96Ab7FiZx1ujYdjEFK0q5tfayD8J0ZC+Cs6PA=; b=ZqQJ/MpnKAX6HikhYBQNlllGVVetxwpVjBNQMzdtUOw64zyQlJvRdsEzTtojB3/tXOeSZ7E1bXphUvrLjVAqmjyrNwFKylT5WQ1gm839XPs1NUvaxZIzNLZtLMZ54S13wCU9/seg4ScF3lUFCFfD0k+O2PIkeAx6RBQ7fJwh9OrlNgz7Fk1/BPB70AD5pFNDQEzTAZKL8VIRVwYUyrrgKKZjCtkHmw7CPZ4FmhU/kAlC6g/T43OyqXFU3Qi4W6jMzxoC8aHEvtMdeTnGt1czz6c6aQjeAMUXtICpFbfgQ+hXbNFfjOo0DQMLdLB1vFObYhneJUcnKj0xBu5YRsTA9g== Received: from BN9PR03CA0080.namprd03.prod.outlook.com (2603:10b6:408:fc::25) by BN7PR12MB2594.namprd12.prod.outlook.com (2603:10b6:408:28::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Fri, 9 Apr 2021 08:07:00 +0000 Received: from BN8NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fc:cafe::ac) by BN9PR03CA0080.outlook.office365.com (2603:10b6:408:fc::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.19 via Frontend Transport; Fri, 9 Apr 2021 08:07:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; gmail.com; dkim=none (message not signed) header.d=none;gmail.com; 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 BN8NAM11FT019.mail.protection.outlook.com (10.13.176.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 08:06:59 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 9 Apr 2021 08:06:59 +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; Fri, 9 Apr 2021 01:06:57 -0700 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Adrian Pop , "Michal Kubecek" CC: , Vladyslav Tarasiuk Subject: [PATCH net-next 1/8] ethtool: Allow network drivers to dump arbitrary EEPROM data Date: Fri, 9 Apr 2021 11:06:34 +0300 Message-ID: <1617955601-21055-2-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1617955601-21055-1-git-send-email-moshe@nvidia.com> References: <1617955601-21055-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6f2375e4-e143-4419-0b32-08d8fb2e73ca X-MS-TrafficTypeDiagnostic: BN7PR12MB2594: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OE/uyWygrP9o8oW62id4c8JgPqU4wZOpXQ+gf6FYT90vfgArC04AmRMp4l/1Ty7c8ranhVIqJfxII8KwSD7O2YS5AkEDkneQGTv5+oEk3t8uhfm3wMyG8vs+dtsIiOREnCMXGPj0W5SJXsExgqaPhOqzAx70iHaTayAoix53S6CLn7N5h5F+Zzn6lzs7xFyU4iMyvx3P65IhJDbW1rflN07HwSd3YuR4JqGhp6IDITCeHZyY6Ki5db7I/9Rv42vWN6Mkt4VTdY67VT/hVHtzAii00bbbEJwRzhpzpdq6cpa+L/iBW/4S+wwFiGkDXVv6eCS9vBofcsvCa55dgBi7x6rTTXHcTUgI25A/JfBZ58zOkkszaqzlW4+ySWS5JnNHCSDPZwp/xBehIadLqspCnEUrkofTbbr0EsNx62GRk5AHuCCZdqjeow2FwThRqMlQm5qNzpY4yZMF4Y7LqraM8L2m6Hce5aeR89plf+1YvF1pUIWvJfnF7tU2PLRG+EQbx/STrbcF5blU7AQLE9JypK5ZCHCYI3IYUb42EvuQjQeBG/z2hx5FQQzpWKgTXUIr15sOraHb2XesdG4yj4DFldOJdq+ErKUNHpm9fiIKCTGWhn4tIV495f01LxWuuLzq4lNoZy5izatdKwbtYUWzWTq3jmo1OraCpyP/WB7OxK4= 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)(396003)(376002)(39860400002)(346002)(136003)(46966006)(36840700001)(36756003)(86362001)(26005)(6666004)(82310400003)(8676002)(110136005)(478600001)(83380400001)(54906003)(30864003)(4326008)(8936002)(186003)(7636003)(47076005)(356005)(336012)(426003)(5660300002)(36906005)(2906002)(107886003)(316002)(82740400003)(7696005)(2616005)(36860700001)(70586007)(70206006);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 08:06:59.9985 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6f2375e4-e143-4419-0b32-08d8fb2e73ca 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: BN8NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR12MB2594 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 | 171 +++++++++++++++++++ net/ethtool/netlink.c | 11 ++ net/ethtool/netlink.h | 2 + 7 files changed, 270 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 fd84f4ed898a..77e4a838f247 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -1338,6 +1338,38 @@ in an implementation specific way. ``ETHTOOL_A_FEC_AUTO`` requests the driver to choose FEC mode based on SFP module parameters. This does not mean autonegotiation. +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 =================== @@ -1415,8 +1447,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 5c631a298994..7106c73fca34 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_module_eeprom - EEPROM dump from specified page + * @offset: Offset within the specified EEPROM page to begin read, in bytes. + * @length: Number of bytes to read. + * @page: Page number to read from. + * @bank: Page bank number to read from, if applicable by EEPROM spec. + * @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 @@ -412,6 +438,9 @@ struct ethtool_pause_stats { * cannot use the standard PHY library helpers. * @get_phy_tunable: Read the value of a PHY tunable. * @set_phy_tunable: Set the value of a PHY tunable. + * @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 @@ -517,6 +546,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); @@ -540,7 +572,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 7f1bdb5b31ba..9612dcd48a6a 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -44,6 +44,7 @@ enum { ETHTOOL_MSG_TUNNEL_INFO_GET, ETHTOOL_MSG_FEC_GET, ETHTOOL_MSG_FEC_SET, + ETHTOOL_MSG_MODULE_EEPROM_GET, /* add new constants above here */ __ETHTOOL_MSG_USER_CNT, @@ -84,6 +85,7 @@ enum { ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY, ETHTOOL_MSG_FEC_GET_REPLY, ETHTOOL_MSG_FEC_NTF, + ETHTOOL_MSG_MODULE_EEPROM_GET_REPLY, /* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT, @@ -646,6 +648,23 @@ enum { ETHTOOL_A_FEC_MAX = (__ETHTOOL_A_FEC_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 c2dc9033a8f7..83842685fd8c 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 fec.o + tunnels.o fec.o eeprom.o diff --git a/net/ethtool/eeprom.c b/net/ethtool/eeprom.c new file mode 100644 index 000000000000..8536dd905da5 --- /dev/null +++ b/net/ethtool/eeprom.c @@ -0,0 +1,171 @@ +// 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 705a4b201564..5f5d7c4b3d4a 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -246,6 +246,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_EEE_GET] = ðnl_eee_request_ops, [ETHTOOL_MSG_FEC_GET] = ðnl_fec_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) @@ -931,6 +932,16 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_fec_set_policy, .maxattr = ARRAY_SIZE(ethnl_fec_set_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_MODULE_EEPROM_GET, + .flags = GENL_UNS_ADMIN_PERM, + .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 785f7ee45930..4305ac971bb0 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -345,6 +345,7 @@ 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_fec_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]; @@ -378,6 +379,7 @@ extern const struct nla_policy ethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_T extern const struct nla_policy ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_HEADER + 1]; extern const struct nla_policy ethnl_fec_get_policy[ETHTOOL_A_FEC_HEADER + 1]; extern const struct nla_policy ethnl_fec_set_policy[ETHTOOL_A_FEC_AUTO + 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 Fri Apr 9 08:06:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 12193263 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=-18.8 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, URIBL_BLOCKED,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 DBBF6C433B4 for ; Fri, 9 Apr 2021 08:07:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3D7D611C1 for ; Fri, 9 Apr 2021 08:07:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232286AbhDIIHS (ORCPT ); Fri, 9 Apr 2021 04:07:18 -0400 Received: from mail-mw2nam10on2040.outbound.protection.outlook.com ([40.107.94.40]:45296 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232087AbhDIIHQ (ORCPT ); Fri, 9 Apr 2021 04:07:16 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MQpMtNXfkPPQcGc7VyQc/jSDihyk9nwNQQjzV7h6P3RreyQ5HqGW9tSO3Vud2rwoIxWzb2ztJ9q9ZY0TJnxUFWzRLlT/1b4dcvWBFCb5CH97qAWkmt6GnEqA15/GFov/F+OOMCKbDBVH+9QVo+HS972QlK1HevkKMLj8CHahUF34UG7bAwwBDWOlRKJe3xnvTMed4MGokfBuAcia9UwBC6dkM/oemU7sVZor+lYqQ+w07W995lh1r+dNJC2h6ctSqA9ym3Wh+8SjLYqJxwT+7xH24l+/nsYeSLFdf6wulDuxGpBInGzpYgJ0vesnNpH7koumbU8Pq9Cz7bZYIcAgoQ== 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=D3BQRlYcIz4sd9lg3GTStb0ulOjwx4PESHY4Ryhdj9IpiOSveH+pb7Qdazb3KJ9HPVL0Nhp8RRMO9EaT2nYhE2YsXSCbvzGpkb4GkF1ssX/lO82MTJZdkh8GcbTL34hYcOAu926T3+W45lYv2nPZJN7brbQpNr00TFokge+AHJTXhv7A4dHgP2YOvP+76MwObLN/HeOUvqGUAPnVYJ/ZCRZt0+tDwhlocWZTx0BKmt8nM5R5M+BA4qRLWHkOL78m5lmuxBRLBcRSHR7hwJFN861n5kiQR0SDTfB8g76+u5ydq8BzWWEosfiUMjIQXrmV1tcA4at+AR0K28x/ZZyR3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=gmail.com 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=NJEyHpT619aSsuBIY2OxDVPzXbalyGJpdybh30Mc0Ycj7KBv3M3gObcRE04QWjPSUg7OugW9G3sDX7Q0zDynD102liy53eR4kp/r3QMVI0yrxUYWGyuJoOVLgJW2YikeDHHM1JFispqhB5eRDwpJNJiULIsiQeiKi76vq+NQ8EcrQiL6av8eo9Y6VSLrL3tqKthNke9apYDPXgJy7h/2d3ctuSnauCEiCirpfLzSLtN2XP8MBkux3hsPAUTPcUnDcQayX9WL6lXes0Y0hazK+HHCEbOXE1Ft+kf4SAyoe/CnHVhnBeZggLdcnp8S9l8wTrdnrKz3ns0hgIZKEhC+5g== Received: from BN8PR03CA0017.namprd03.prod.outlook.com (2603:10b6:408:94::30) by DM4PR12MB5341.namprd12.prod.outlook.com (2603:10b6:5:39e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Fri, 9 Apr 2021 08:07:02 +0000 Received: from BN8NAM11FT036.eop-nam11.prod.protection.outlook.com (2603:10b6:408:94:cafe::de) by BN8PR03CA0017.outlook.office365.com (2603:10b6:408:94::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Fri, 9 Apr 2021 08:07:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; gmail.com; dkim=none (message not signed) header.d=none;gmail.com; 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 BN8NAM11FT036.mail.protection.outlook.com (10.13.177.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 08:07:02 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 9 Apr 2021 08:07:01 +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; Fri, 9 Apr 2021 01:06:59 -0700 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Adrian Pop , "Michal Kubecek" CC: , Vladyslav Tarasiuk Subject: [PATCH net-next 2/8] net/mlx5: Refactor module EEPROM query Date: Fri, 9 Apr 2021 11:06:35 +0300 Message-ID: <1617955601-21055-3-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1617955601-21055-1-git-send-email-moshe@nvidia.com> References: <1617955601-21055-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cd8b63d4-24c7-4e5c-5900-08d8fb2e750e X-MS-TrafficTypeDiagnostic: DM4PR12MB5341: 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: gPJOxlgbIygUZeJf/eBmPoNUfvKvHy/icmx0i9I7lFTlQ7fKcrQ4evUjLiGP5bIkK1eobDknZiW6F7V/qDNZhYsgDIyqoiczVRBnwEJoHssFn1y0Djly0HTRGp0GmSwlWZtIz9LnHr0LmemSFOSdLxiiljak6aU+WXctq1M6uYhVbXrJsuB7IFnWyFuvDL1tx09/hmCF1t9L4nYpwI1Px6E/XSCwcq7DPG93IRVjU+sjIa2kSGr9/hQ94QeF1G8l6C61t5GqgrCrODr4qP/c9Y6Vz1ypdrKnJYra0EwQZzoJyqRtghkKW7eTkGiYwZmi0ZuL5GWoLu/1Sc0I1BS79IO+ESLklcLmx8Izqcn/aj7525IkazFmIrf5aDuSAjSPX6YLPRzA8D5Y9irChyRzn+MV318OajySd8oRAoYnoANKXZmjXloq0XDAi6UzRhuowVjr//WQjTKTPI4vBMvp2P/PCe17G8c66ec/yiclbJ15bDSlfPhi4BxTfhgAbOeurhaI/TWLEhIfZdvyaLJQLA48bnwPNyEXX7uovtDa2TR6i67FXThZI8RyxJ7LcBi4xR9HhseS8ACdrD3a9j2jTqDdgKbyKLuGEAbFC92D7uWfrIL+0aRMYSrj+Z8xzUC/lzFM6BaT+VBgfjN3cmD3+Q== 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)(346002)(376002)(136003)(396003)(36840700001)(46966006)(6666004)(7636003)(110136005)(478600001)(70206006)(426003)(54906003)(186003)(8676002)(36906005)(2616005)(316002)(36860700001)(5660300002)(336012)(82740400003)(26005)(86362001)(8936002)(2906002)(83380400001)(82310400003)(70586007)(356005)(107886003)(47076005)(4326008)(7696005)(36756003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 08:07:02.2068 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cd8b63d4-24c7-4e5c-5900-08d8fb2e750e 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: BN8NAM11FT036.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5341 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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 Fri Apr 9 08:06:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 12193265 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=-18.8 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, URIBL_BLOCKED,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 7C5C3C433ED for ; Fri, 9 Apr 2021 08:07:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 56402611C1 for ; Fri, 9 Apr 2021 08:07:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232344AbhDIIHW (ORCPT ); Fri, 9 Apr 2021 04:07:22 -0400 Received: from mail-dm6nam12on2059.outbound.protection.outlook.com ([40.107.243.59]:5729 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231809AbhDIIHS (ORCPT ); Fri, 9 Apr 2021 04:07:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iJazUICH4xt9tmQ++3IR97NVohau5VR2M+7Nelw7agMS541jeNTPf4Um6wFKvd9x2b5axnqTexGHLiSSsmJ0gTkAhqBNkSk5MixV/+fBiLBNrtmJAx+bQddezt1Ie7Ym0duay2OQUvAVKqxcs3b3R4RRK0NB0tMKI5gBzUy39koD6qlm0WvbKZJ4vv8i0h/Tw9AJb2cf4XTtSqIMLhObLZrHfUEP7ESzD1cEMSsifaIDeelRy9hLnlG1ClNCnK1DXZyLKVTLGBaJp0tIPNCWQPVJ4F9Q1gpqnLTybE93G9KPWG4s2PgNFW43DZZgpq9Hy9/Oz0+jRKiTuhqgEuRahg== 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=vz1q2sg+oLaptTK6i4CqbSwVWCqumj7HCixQYTMc2dc=; b=DFK/sGN8JvIv/9LBEh16s1DvkrPFbTi+pdsG29/9nUAbnWG5bvJijG/BOTzE5OYlnC7F7Pmky0BgbpVK7FqoGpL9DUDJqzTVhYt5I8ZUF4bfefKO4glTFJbSpvF9rOERN62yAZsVkDQRIyYZ5T2StgSd9geWQTZYYAfpWTwJoF467jezCNa3Odtuks6oUd2BxTmGVXKyMwLi9dgsJ9LitipjGa8Dui5o5U/5yxTU9ho+UgBfSVChmkWEbZDLF3Gu+odGCyZ7KQ8+HxTLDJ97A+0I7T/0Q+0FxUSGyN35UxgyDw9eMn2T4++42W+5GlJeSk10nFkkLr4yhCZb9fpPFw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) 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=vz1q2sg+oLaptTK6i4CqbSwVWCqumj7HCixQYTMc2dc=; b=LfxV7Ug5cuslMKkEnftkaB4yHfm8MdSisSNRvje9XFaD1wIfttIKLmtm3tLyxiILfjgS3EYoAVJyLD1LgiyAZkneLSEzswUWTMPcMtXqOJXdrob0sb0a/qdK7c63eAwNEWZ1v4WM2ZKKwdmJv1x8DoISci5hyy7Fp4Jv4zCl4Rta+1lIN/s5ggH4B/+6LLIIOa3zF2zOD3diEbFpcOjyeO6fggto1gtjlv0JfxDjah1VivKS6a5L2xVBSnjYP4dXrdr0nhvFc2ugIj/WN9UXWlyLdSIShdvZvorxkkjGyYBOvJHz91sLVw1FW9V7tTHHE0YnsVepYfFiMSaOaYOKwg== Received: from MWHPR14CA0062.namprd14.prod.outlook.com (2603:10b6:300:81::24) by MWHPR1201MB0077.namprd12.prod.outlook.com (2603:10b6:301:55::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Fri, 9 Apr 2021 08:07:04 +0000 Received: from CO1NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:300:81:cafe::f6) by MWHPR14CA0062.outlook.office365.com (2603:10b6:300:81::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 08:07:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) 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.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 CO1NAM11FT068.mail.protection.outlook.com (10.13.175.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 08:07:04 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 9 Apr 2021 08:07:03 +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; Fri, 9 Apr 2021 08:07:03 +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; Fri, 9 Apr 2021 01:07:01 -0700 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Adrian Pop , "Michal Kubecek" CC: , Vladyslav Tarasiuk Subject: [PATCH net-next 3/8] net/mlx5: Implement get_module_eeprom_by_page() Date: Fri, 9 Apr 2021 11:06:36 +0300 Message-ID: <1617955601-21055-4-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1617955601-21055-1-git-send-email-moshe@nvidia.com> References: <1617955601-21055-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7bab2ef0-64cc-4764-6e8c-08d8fb2e7653 X-MS-TrafficTypeDiagnostic: MWHPR1201MB0077: 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: vwCW6YvS+vOBzY/3/g76dzrVXAisgjxziVB4LsmIVIZK9WqiZGoOkK13MwvXEjST4+4Ye42YFvudap6CayaElVB+J2bAheKcXUYxszkp9mj2zbfH+zaWRA0gD+n4pvlfr+muREahKmtdUJosU/0S6HtUaP5tjxp55xq+3Co+32o68JN3s7cqFtVFyV6J+EfOTEIl0iwEjkwV9Ll3FVZ10TzbQ5OU3EwJZwKs09Rntl6g1GuYCRE2/TReRfJApaNsPHaWNL3n4HYYesRJ2WMRV2+joGJis+bEDxFSnRFCXx9aHn/OurbPAFxK6zOsCeZ0Z7c66h4Nyp1V9NQ02uB9HweVmrRoR1LZfk6Z89v4mLTKyjnClj3wD0FfjBvhOSs07eHj+HkBHn5tiq3yJttn8lLZLoH1Mq1UrXocM332SCZAKdyRrX45QcZ1FkZ7yfxgufJJSgzOITwkVw3lrc2jhTB29uwsWv6ddokR33iCjYy5LVegb1F/FhIWmtiFTItyIL2lwG0DEAzZOJN9gH8y4DvOUVdBb1qcNFb0lrg2j4Iat6pLB2cfyRfb3wqVk38HVQXybA+ecwTqlYu5KwaEQrTaSpMEG4Q29pfXKydZfRFLdPJ+JzAvRY/P5sKehvBgAUSbKkQwS+ni5AdsMMGRHSQLN7z3h7IRPj1BdG0PMjo= 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)(136003)(39860400002)(376002)(346002)(46966006)(36840700001)(478600001)(8676002)(47076005)(36906005)(336012)(5660300002)(426003)(8936002)(54906003)(2616005)(110136005)(36860700001)(316002)(7636003)(83380400001)(4326008)(82740400003)(7696005)(107886003)(356005)(6666004)(86362001)(36756003)(26005)(2906002)(186003)(70206006)(82310400003)(70586007);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 08:07:04.3472 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7bab2ef0-64cc-4764-6e8c-08d8fb2e7653 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: CO1NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB0077 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 | 41 +++++++++++++++++ include/linux/mlx5/port.h | 2 + 3 files changed, 87 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c index 964558086ad6..c238804b0664 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c @@ -1770,6 +1770,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) { @@ -2159,6 +2202,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..522a41f8f1e2 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/port.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/port.c @@ -428,6 +428,47 @@ 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; + + switch (module_id) { + case MLX5_MODULE_ID_SFP: + if (params->page > 0) + return -EINVAL; + break; + case MLX5_MODULE_ID_QSFP: + case MLX5_MODULE_ID_QSFP28: + case MLX5_MODULE_ID_QSFP_PLUS: + if (params->page > 3) + return -EINVAL; + break; + default: + 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 Fri Apr 9 08:06:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 12193267 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=-18.8 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, URIBL_BLOCKED,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 1D3B5C433B4 for ; Fri, 9 Apr 2021 08:07:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ECFE8610FB for ; Fri, 9 Apr 2021 08:07:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232395AbhDIIHZ (ORCPT ); Fri, 9 Apr 2021 04:07:25 -0400 Received: from mail-bn8nam08on2063.outbound.protection.outlook.com ([40.107.100.63]:37344 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229545AbhDIIHU (ORCPT ); Fri, 9 Apr 2021 04:07:20 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ofmouUNGR95X0DPsoRzLdMvQg/bxuQSFqW65K7uq+JGzDfXuuLm9aAX0cXSG25rnoOTRVO/3YpFoPtaYOiVwDwPautjjoxJ2QV7kZY3fm8bk25pGeZWqq9uCY0gA4uu3VySgL+d77EEzHBnF4wJxtS6i7LQPejW5aqcHQJjwK7bnCKhwE8/MDLBvmuMvWPhLaWFY17PDL+EnjNvuIcj1wUsZJ/Q8yGzOKTj35OwJqjJN+dEzekFMRPYLV5Otdelly2r8A6PoeipHMHpVQPBk5FehpSKh0JEQuGTpnuFQNF3sNEGz+g6unTjBVqGBoL4XceTdNqstUnlrzerxfAXIfA== 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=+a8GJ0x4AiDELPzHGM35qkpiShueSIxODpvNpMM/XMU=; b=Vqdmr1sXhrKQXfNzb9prY31B7oPE7RUF1TNHiOcQsHcv61tVVF2L+HDndlJnL13aSXXHiD1/rp4+EFIy3I8FgmwVx4j25EerCG3Cnu9EVKnkI+RBT6tdOR6UQZGRKyMHnIApOHy+BRSG8IXI9X/7SWceH3QHkjPrl7FgzAbACMYQFvV4kVphGZP7HNWdDcly8QD4id3pvgwILMoCFADm8mZI7j2CjvxVVBLWppDnZFP6NAV/fKGcLCSeCfrpL2m6hYWhGg45BXxpjq4M9vWvNDtRIPXPHNJsjzOK5v49kI6ockEV4NycGLAa8pEo5yQxGX8Hku5a/6+JkeWX/uQNFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=gmail.com 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=+a8GJ0x4AiDELPzHGM35qkpiShueSIxODpvNpMM/XMU=; b=ddlyzqYIVEUPay1NySTW+U57fORSw4/s1khq14u9/WfR4Ds51JrR2Vo6OrDiPpnTXM4D7iCi1Q2P2N4mDA7WBokPBcqEZDxylWSlWnwZFJRD9sjNd4ECz1JMdKFXPks9zHGeAwDIPw2Fh4YNRhR5Nch61HEK8DTdImAil9KJgqOiiNUh0A75o5Ub0RuQ6O1vqbrpuWRJL+vRtC3s1cbjHbA5yIYx0zO71oukSrZBuNOdXVGEeA/FLS3YDukwwLTsJVPemazGUMJmnNHjoDYNMNv+dINWjIzAV5fdm4R+n8A1qi9rGBxGT1Cdeet0qxtDmmS6dCM8TAnPgdlWLJScpQ== Received: from BN8PR15CA0008.namprd15.prod.outlook.com (2603:10b6:408:c0::21) by DM4PR12MB5055.namprd12.prod.outlook.com (2603:10b6:5:38a::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16; Fri, 9 Apr 2021 08:07:07 +0000 Received: from BN8NAM11FT064.eop-nam11.prod.protection.outlook.com (2603:10b6:408:c0:cafe::8a) by BN8PR15CA0008.outlook.office365.com (2603:10b6:408:c0::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 08:07:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT064.mail.protection.outlook.com (10.13.176.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 08:07:06 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 9 Apr 2021 01:07:05 -0700 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; Fri, 9 Apr 2021 01:07:03 -0700 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Adrian Pop , "Michal Kubecek" CC: , Vladyslav Tarasiuk Subject: [PATCH net-next 4/8] net/mlx5: Add support for DSFP module EEPROM dumps Date: Fri, 9 Apr 2021 11:06:37 +0300 Message-ID: <1617955601-21055-5-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1617955601-21055-1-git-send-email-moshe@nvidia.com> References: <1617955601-21055-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8f043a48-b660-41d1-39ea-08d8fb2e77c8 X-MS-TrafficTypeDiagnostic: DM4PR12MB5055: 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: JJnePyYZMMyFWZkO15pHtGaOUguwrTIckkQvvsprmrdlJmXyilF5hDR4yxEir9ReyviF5uMpmtX2rWK1i28zoE8+gpIdjsdEhtJq7OqCdb5+u+11fypFXDBsfrqeE4BX9AU1Wz+gF9gLSNZNcQQ+Zf37UvX8Dp/6edvmfwm3umPGAVuaYR0ght/ncoQnsY210FZmB0sckCvG6SnO49FfbOK4tty8u/pShfoeUuzzqROFZcfUeyh9jM+iPGMgQuwGaBzyfxIcjNhG7kXUFUfloLzbLaBBXiBWRPXrGxgxd6zuKNIs/ORAgAXa3waYSnpkzkhsLqZTYyPEbzx0exEbuPRgguOP8je214I/SqxVPM0cm2roBI1BsEhJr8q20dLtJa654wrROVuDGJoB/K4zOaiqSi1lTpOm8WaD5Wj/nFvyZTQiVx9cerrhqUVYkopojlfINAYR5J3zvV+T4m1mn0VlvMLHzY5k1jrT9N6e62CwbS5zOsJlgWif3rngtQC1XSpsPWe2iN+vlQ+lAsfJs8InvKHT8cSneFMfhGtMCjsLZanI2c7dV4ligvORdrpIwN6AgGLr9fd6Ol5hbJ5FiHsl1alY3Y0ZrNeHVEOPY46U7FtNTi6QhVW4BB+o07vOSK0Y28iRrCANHJJ2mE3YVA== X-Forefront-Antispam-Report: CIP:216.228.112.32;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid01.nvidia.com;CAT:NONE;SFS:(4636009)(136003)(376002)(39860400002)(396003)(346002)(46966006)(36840700001)(54906003)(110136005)(478600001)(86362001)(2906002)(36860700001)(316002)(26005)(336012)(2616005)(8936002)(82740400003)(70206006)(6666004)(186003)(7696005)(47076005)(36756003)(8676002)(5660300002)(7636003)(107886003)(4326008)(82310400003)(426003)(356005)(70586007);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 08:07:06.7834 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8f043a48-b660-41d1-39ea-08d8fb2e77c8 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.32];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT064.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5055 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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 | 2 ++ include/linux/mlx5/port.h | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/port.c b/drivers/net/ethernet/mellanox/mlx5/core/port.c index 522a41f8f1e2..1ef2b6a848c1 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/port.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/port.c @@ -454,6 +454,8 @@ int mlx5_query_module_eeprom_by_page(struct mlx5_core_dev *dev, if (params->page > 3) return -EINVAL; break; + case MLX5_MODULE_ID_DSFP: + break; default: 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 Fri Apr 9 08:06:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moshe Shemesh X-Patchwork-Id: 12193269 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=-18.8 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, URIBL_BLOCKED,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 ADB67C43460 for ; Fri, 9 Apr 2021 08:07:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E42C610FB for ; Fri, 9 Apr 2021 08:07:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232362AbhDIIH1 (ORCPT ); Fri, 9 Apr 2021 04:07:27 -0400 Received: from mail-mw2nam10on2060.outbound.protection.outlook.com ([40.107.94.60]:38400 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232354AbhDIIHW (ORCPT ); Fri, 9 Apr 2021 04:07:22 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A6z6oa7Gfj8TBogVn8f2pRgCn6FQTACWDpbHMlXPbcq06pCxxMElghBV0t1oaGFH+HuMJV/ZgiP6KglSZ3YV3arUGyAJucHmpUG5eRPr4SCoe6ZVVxwmneOFlx240ydNoLDE2ZXAMVfAz7n70fDRpjJTesptTBs8RXFSXru8YUyTnmRHw3hOCqtIsaGiOlElPAnCR8MILVo4atEm0Mgbyj0j0HA2nvvLnitIR16kkPYXrHYCQqbJHtGNkQbUwG7hKqApPngAMnyOXFR3lqN8JUGJujI28gXFFPlcUTXCMC9XkjeFaeTR+fQY2vlYeHP+hpg1avcPBb7EngkripW9mA== 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=t6edmMsgQ9e8pPqXPNeaBNpO6k9utqturmvl4/R/bi8=; b=NUM0mik9rmddiZ/KEuEivq7HlJYBnaXi8A0cqL8M6NJBO9nXYo01BqsS0DH7WjHIpthVnemwLt8ST9b9j1qk2gRJAATLtQbIIMo9Z38XkCaNiOlKtaOTukLmYqQQ7lk6kwBMkJm6A12kpPy+J5TifdO2kkVSrg5BwzTKZNpTaf5R3vJTGd7tg69uYeZ6LhXSqUidMPEEm9uakzgTzarfMjEOiUUiKYaIr+c1VwQM+05nyMvTfbc+yUuJwkBP+TtVkTZ60YxtoXGNEtdJnUnpYbeh3avErr8Y2czlJAuU+TRYY5RU8ojFi5IvYdA+ZhqPa5hmCZ/TJuzWYbF17HAZoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=gmail.com 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=t6edmMsgQ9e8pPqXPNeaBNpO6k9utqturmvl4/R/bi8=; b=PUJzrytCIwuIYjVgoOgB1ngM3+pKWfhqTEu4W61IuBfkT+3b7bGMtcBk3AEc4dyqc9OepAn3fnG3rbU3MwmRkNHymJX/hC6Ef075/OihazYY1nOZPV+nEkphORT6Qv7SwqpKIO8zzKg2dWnUznkscKRm92I/Gvt16ZIK7LhgL6OgqIwjH20Bt4Hj3TJJrGKNVRmNbWtWJ3TmUWnzihkxbcBll8Dsl6u+Cr+MbAAPtPbZ54OjONRAbaTzFvdD3Uv/q+Hajdpx3dkzmH6P+qHMaH5aAOPxTnJCkQi9Q6iY3bLlR9Mj2R+PL8jvf3O/lr3DXifNeoVI5/zpyyicK/NBQQ== Received: from MWHPR13CA0046.namprd13.prod.outlook.com (2603:10b6:300:95::32) by BY5PR12MB4855.namprd12.prod.outlook.com (2603:10b6:a03:1dd::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Fri, 9 Apr 2021 08:07:09 +0000 Received: from CO1NAM11FT067.eop-nam11.prod.protection.outlook.com (2603:10b6:300:95:cafe::17) by MWHPR13CA0046.outlook.office365.com (2603:10b6:300:95::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.6 via Frontend Transport; Fri, 9 Apr 2021 08:07:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; gmail.com; dkim=none (message not signed) header.d=none;gmail.com; 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 CO1NAM11FT067.mail.protection.outlook.com (10.13.174.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 08:07:08 +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; Fri, 9 Apr 2021 08:07:08 +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; Fri, 9 Apr 2021 01:07:06 -0700 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Adrian Pop , "Michal Kubecek" CC: , Vladyslav Tarasiuk Subject: [PATCH net-next 5/8] net: ethtool: Export helpers for getting EEPROM info Date: Fri, 9 Apr 2021 11:06:38 +0300 Message-ID: <1617955601-21055-6-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1617955601-21055-1-git-send-email-moshe@nvidia.com> References: <1617955601-21055-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 408272a0-1f0e-4f45-62c0-08d8fb2e78e7 X-MS-TrafficTypeDiagnostic: BY5PR12MB4855: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4pa3YI6RfqHzB8sgNEnGPITIXjHzYH34gdgxa9LnDM3z3TXqa4fVFJqTEMgXRYYSlZqra7PlOcJJphIP+XeukVNvgwHS1LgRuTXiUDEdaFBuUtT4Yb0ZaeTWHAkdRNINfRbxHsASfcIM2ASSMNMoH3KZlViZOkz+nqAFzuoIMLW8FdWOlq2jtrA+NhgDR1y5SC3k2e1D9E1e9TuT3L3NmYUb6ci1VzNozC5sGbA6Btt2aNMXZg+v/6RkOGX0NIY2R2yOv3iXXHFQrpY6zwufwSdZcfNmKfPkFFY7qoePjKK0rROBwc2v8aGiTmV9qnRn74eFIVXDnLZcxghOYSaJxKV0XvmpE6IIkrVsgus+wjzAP0yHTFzs/MdSAkKuP6rAKCquphRiLM8qTUkKwLxfh2avbi92MNllTrTP4H2CjgC4YD47kS8NKcGGZTrRqzhK6kU5I9N69q7ZO5ifn2reYzLz5suQNrzqVvSZqMGNVnKnqw+BD8ZJrQkLPQKhgMpL70qd/TvAGgrHBAHtZ8Rsifg1xi5cFi6b0Wr9y6jZyUO+iGM3SnLRo1eRlyolH70ayOVyeauZHEcJpdbwus4wABMrk6Kt7CaohQmYe4QWMmaUn8GsfWHGloJrAoELUrQu5B7/u8xVc6NwHc2/xsOBfT5dr0/vcWDmrlEei/emSEs= 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)(136003)(376002)(346002)(39860400002)(46966006)(36840700001)(47076005)(5660300002)(82740400003)(7696005)(86362001)(70206006)(83380400001)(70586007)(8936002)(8676002)(110136005)(54906003)(2906002)(356005)(316002)(36906005)(107886003)(26005)(36860700001)(186003)(426003)(6666004)(82310400003)(4326008)(2616005)(7636003)(36756003)(478600001)(336012);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 08:07:08.7303 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 408272a0-1f0e-4f45-62c0-08d8fb2e78e7 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: CO1NAM11FT067.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4855 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Andrew Lunn There are two ways to retrieve information from SFP EEPROMs. Many devices make use of the common code, and assign the sfp_bus pointer in the netdev to point to the bus holding the SFP device. Some MAC drivers directly implement ops in there ethool structure. Export within net/ethtool the two helpers used to call these methods, so that they can also be used in the new netlink code. Signed-off-by: Andrew Lunn --- net/ethtool/common.h | 5 +++++ net/ethtool/ioctl.c | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/net/ethtool/common.h b/net/ethtool/common.h index a9d071248698..2dc2b80aea5f 100644 --- a/net/ethtool/common.h +++ b/net/ethtool/common.h @@ -47,4 +47,9 @@ int __ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info); extern const struct ethtool_phy_ops *ethtool_phy_ops; +int ethtool_get_module_info_call(struct net_device *dev, + struct ethtool_modinfo *modinfo); +int ethtool_get_module_eeprom_call(struct net_device *dev, + struct ethtool_eeprom *ee, u8 *data); + #endif /* _ETHTOOL_COMMON_H */ diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 26b3e7086075..eec8e588894b 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -2204,8 +2204,8 @@ static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr) return 0; } -static int __ethtool_get_module_info(struct net_device *dev, - struct ethtool_modinfo *modinfo) +int ethtool_get_module_info_call(struct net_device *dev, + struct ethtool_modinfo *modinfo) { const struct ethtool_ops *ops = dev->ethtool_ops; struct phy_device *phydev = dev->phydev; @@ -2231,7 +2231,7 @@ static int ethtool_get_module_info(struct net_device *dev, if (copy_from_user(&modinfo, useraddr, sizeof(modinfo))) return -EFAULT; - ret = __ethtool_get_module_info(dev, &modinfo); + ret = ethtool_get_module_info_call(dev, &modinfo); if (ret) return ret; @@ -2241,8 +2241,8 @@ static int ethtool_get_module_info(struct net_device *dev, return 0; } -static int __ethtool_get_module_eeprom(struct net_device *dev, - struct ethtool_eeprom *ee, u8 *data) +int ethtool_get_module_eeprom_call(struct net_device *dev, + struct ethtool_eeprom *ee, u8 *data) { const struct ethtool_ops *ops = dev->ethtool_ops; struct phy_device *phydev = dev->phydev; @@ -2265,12 +2265,12 @@ static int ethtool_get_module_eeprom(struct net_device *dev, int ret; struct ethtool_modinfo modinfo; - ret = __ethtool_get_module_info(dev, &modinfo); + ret = ethtool_get_module_info_call(dev, &modinfo); if (ret) return ret; return ethtool_get_any_eeprom(dev, useraddr, - __ethtool_get_module_eeprom, + ethtool_get_module_eeprom_call, modinfo.eeprom_len); } From patchwork Fri Apr 9 08:06: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: 12193271 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=-18.8 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, URIBL_BLOCKED,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 089F7C43460 for ; Fri, 9 Apr 2021 08:07:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D73FE61182 for ; Fri, 9 Apr 2021 08:07:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232583AbhDIIH3 (ORCPT ); Fri, 9 Apr 2021 04:07:29 -0400 Received: from mail-co1nam11on2043.outbound.protection.outlook.com ([40.107.220.43]:62816 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232087AbhDIIHZ (ORCPT ); Fri, 9 Apr 2021 04:07:25 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Znvyb1AgTZiJYClfsJYUN0KqfRpQahbV8R9ZbIy4OauR7V0KeCkMXq2l0koc5nKctrjv/WiUUcntXEc/yDoHsZ6lQR8gpqhux4U5D1XgHy0FbRsbTXuOh36g2njObFerdZji6CP+ooj/f12kH8Y1v3fSyTVM4q1hzNLTYX00DerxjMCw7E8w1uSOaQJmbPgUG/eFcEMTyaImn/DHJpEWNO9PwVjkZAEK4ueA6SPp9qJ5Nzamz1YLSr2jroXXRR+Jq/nQQmNF8+Ed7a5qsZxauxJS9ooK0AzQ7t4XrUQYJBNUuFWUOoKqnsGH2a9byk44aDZ7n2yCs8dM9HMQKTCT4Q== 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=SRjDAJ8OUpkf4M2DTeycMtAZ3N1WoRIJrhaWSnjaQlo=; b=gTcs3LFPPyRgafL/ggNhtJyzYGMMZHNFPnRXVAc3wOKUzr3PmxQezbILhLefEbOdy555XelnYJwhLzv+KXgU0HSYkfI7MUJ2/rKgZnnqiQ4nA7MM2+h2K/Uu9N5ObrFqcyM5jnU5JHnnfwKhcfwXzFGci7omTNgwmc61E9R7tUq1Ci7q88esabKY01HPyNjUsgA8ZQiIsuO+2ZPatxCgLcL+MU8Gz0wRY5X80XgYViXqiPho/WwokRb/vaYEwyaSrUS/VikZIOqX2tAOA4o68ZxQXhMxtKXwili+/NCGin0H6G5nMh8dpywo8RglEWZ8H6T5GoSaGzNP9oleh5Rqlg== 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=SRjDAJ8OUpkf4M2DTeycMtAZ3N1WoRIJrhaWSnjaQlo=; b=lir+KDJE0edXQbN/OeUavxvEzR0C0cmKVc5eQQFv+P2kcZXWaLXbKhzwgpPHzWjHhjqn/4EzyTqMa4WZDuvOpiWEc/Ro33M5YVj28ZMonpSbRSySf4uRRSPywZ5IFAbFtSnGS+sYhjDVInieYPTues6wMBmtHKZpS+YthCEMUfoVXaKs5Z6eEFEmuFDBpgqo18bpmEEODn5d8wjIpJEElrc0j34Oi6BD6IBS25C07KO1dYn5MJQeaguw/7Ugvt29lplrjMYKk6mFHNTf8I5DOBM/EIvhwZqVo99tx1R0kbqBEVupvJRmYxxXMI2UoJZScjB/3ReL3246NrTR+kO0VQ== Received: from BN9PR03CA0613.namprd03.prod.outlook.com (2603:10b6:408:106::18) by DM5PR1201MB0058.namprd12.prod.outlook.com (2603:10b6:4:50::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Fri, 9 Apr 2021 08:07:11 +0000 Received: from BN8NAM11FT024.eop-nam11.prod.protection.outlook.com (2603:10b6:408:106:cafe::c5) by BN9PR03CA0613.outlook.office365.com (2603:10b6:408:106::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 08:07:11 +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 BN8NAM11FT024.mail.protection.outlook.com (10.13.177.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 08:07:11 +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; Fri, 9 Apr 2021 08:07:10 +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; Fri, 9 Apr 2021 08:07:10 +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; Fri, 9 Apr 2021 01:07:08 -0700 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Adrian Pop , "Michal Kubecek" CC: , Vladyslav Tarasiuk Subject: [PATCH net-next 6/8] ethtool: Add fallback to get_module_eeprom from netlink command Date: Fri, 9 Apr 2021 11:06:39 +0300 Message-ID: <1617955601-21055-7-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1617955601-21055-1-git-send-email-moshe@nvidia.com> References: <1617955601-21055-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 67f694cf-f7b8-4543-fcfd-08d8fb2e7a8e X-MS-TrafficTypeDiagnostic: DM5PR1201MB0058: 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: dkXDD8kd/rLUBkt2I2KwQw0CWGvHgd/AhDH/g3iUJQIuOZ+r1r95BbMm53iejG0nsIDaN+6e+oPbWoKGrXkhLeKJ1+lfogm842POLepo+TUUobpwyjCR3lwqGCkRq32MWqDTeuJoyac+VTDUk954uWGmKDouCv6APAYbV6XnBzED3gfL9J+tct1JlnG6zpaoMY1V7BgzTrWZnxQzpcTvuzgYMKkfSeWjdz01Pe8hUOHMUs2pKzL9aYp6Od+NtTQfavBfClH6aFvie1V55vKeZUcX8p1mEbDbgMAWEPqzR3AjFKns1Psujm90Ds6VduVOWhN6UEIAlJ4LGxERaPwHd4rCmf4uI6n4sn+JIcy0B23Z/iERcCSMNx1Kg26sNZIUmh1BuZ14hnVflmSgd6FChyPGVmFy2uJaKcmVEjGk69YIVIzUKHYRbtaAF7MV94fGzQPOPB+j4zGAp+ofmYV84zLmArIqOpaEGhtqK6AVH3z5qFyja3AfWLLDLY7rx+kDTlixOS/zrBkYDslKAFl2hbT34pkDq3lZ9isDneAz8sL3wybRZovnG9JvQS67NnW8aQLr25n6+GV+OWeFabnRy42zPKv/y6b6jm9lgsMPSq1L+53w5K06n0H1FZPQcrJhpiLTHc/Z/NPw1OKlFezyw7G7oKxFoTVVSEjSZrkF+LI= 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)(376002)(396003)(136003)(346002)(39860400002)(36840700001)(46966006)(86362001)(26005)(36860700001)(70586007)(107886003)(47076005)(336012)(356005)(83380400001)(2616005)(426003)(186003)(70206006)(8676002)(4326008)(478600001)(8936002)(82310400003)(36906005)(82740400003)(316002)(6666004)(110136005)(7696005)(54906003)(7636003)(2906002)(36756003)(5660300002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 08:07:11.4514 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 67f694cf-f7b8-4543-fcfd-08d8fb2e7a8e 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: BN8NAM11FT024.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0058 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Signed-off-by: Andrew Lunn --- net/ethtool/eeprom.c | 62 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/net/ethtool/eeprom.c b/net/ethtool/eeprom.c index 8536dd905da5..1a49c133d401 100644 --- a/net/ethtool/eeprom.c +++ b/net/ethtool/eeprom.c @@ -25,6 +25,66 @@ 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 * 2; + + 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; + + modinfo.cmd = ETHTOOL_GMODULEINFO; + err = ethtool_get_module_info_call(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 = ethtool_get_module_eeprom_call(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 +96,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; From patchwork Fri Apr 9 08:06: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: 12193275 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=-18.8 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, URIBL_BLOCKED,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 80B7EC43461 for ; Fri, 9 Apr 2021 08:07:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 594016120D for ; Fri, 9 Apr 2021 08:07:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232656AbhDIIHb (ORCPT ); Fri, 9 Apr 2021 04:07:31 -0400 Received: from mail-bn7nam10on2079.outbound.protection.outlook.com ([40.107.92.79]:6432 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232452AbhDIIH1 (ORCPT ); Fri, 9 Apr 2021 04:07:27 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=np8xV2BNdshHvFqr5i4nLon1yZVEYoX9fvP6Yga9Ndz6PLrqS9dyg/5WBKOamBrbS2oEH1U5b3AMYttFY47TeAB0doOdyOwV+gRT+yO7+Erd24ADS/Fz/P1ryzldZZ5qKDjuXoHcNGvKz8foSMOGlg0IhmF1czzVWucRQQy9mkS0J9OO+Lkxvzcyxp5ey0zxppWsZ35WmJCeVBBPRYvb9x0oYixk+Mf0N16cjYNYoZ1p1tHDp9PhHOi3iV4tfARToqw4j9Ya36quSW/890mJDRL2sVFsAkv7+csK95jCu54i8kQhhhUT+gAFReZ2n5tjUkdX+ua3jFMDdUzdGo9nBw== 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=7HHmgDlVK9ldPQmcHYFuRM6C5HFjcsNN9HVQmjzSAxE=; b=LA/EKYUvPlX8jBssVx4xCaFuw9bTVOBvZ50il+hz2ZO+ErmstkfmfprFMlJVlwY2NJcP3lse+PLB5izMYqFYKBD+INljG5YX8ZqFRBCZmJOa9QlYnzL433mB583kSZPSZgplUt7ovHaZiRqNGtgiEMtDTbleGnPr3lyBUBbgl0UZ4n/LUMDQVhkACuhNdPU0+hCVcWgxN4P/M6/mVUkwKxHnHjzwmfELB2busfUzCsJ4OhltT7E0svswL7vOtElBdv70QtvkUJPLsZF6Ge2aqc2/5L9r9eejddeXnK+gyetEuGdC5ndOmvijy1JW/cJ5pXmmxSdSsq6g/0FUrZ4ILg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=gmail.com 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=7HHmgDlVK9ldPQmcHYFuRM6C5HFjcsNN9HVQmjzSAxE=; b=QQvPa5og/U997Hn2fklWgYlNseQpy4hUWutn95Rh2fgRiy28Sl9p56dsvDk5+U11WBEQfR3Km8CY1lmwp4JNRm3lKm1oBTDi0AkQur9He3qW0+PCmzpJYyK5oi7OIYORI459ieII8FfdeBxw3WvW5+QOy21ABRhGZsB6uZsPhv21q3kFPvyd96ABfXtxXlOjLaM3WRDYmWdCPZgzHA3M6xZvkOWS4TsXL1Lenekhvy69LOuawc12y4cU48zmq7u46hFKxgFEyOQvr/Q6/w+mTrlSDUoKB9Mip8VaQSZC0eAHgweDAM0MNaPiTCteCiDNXuqeCkV/sriUc5Dw6EmVWQ== Received: from BN9PR03CA0471.namprd03.prod.outlook.com (2603:10b6:408:139::26) by DM6PR12MB4928.namprd12.prod.outlook.com (2603:10b6:5:1b8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Fri, 9 Apr 2021 08:07:13 +0000 Received: from BN8NAM11FT026.eop-nam11.prod.protection.outlook.com (2603:10b6:408:139:cafe::b7) by BN9PR03CA0471.outlook.office365.com (2603:10b6:408:139::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 08:07:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; gmail.com; dkim=none (message not signed) header.d=none;gmail.com; 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 BN8NAM11FT026.mail.protection.outlook.com (10.13.177.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 08:07:13 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 9 Apr 2021 08:07: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; Fri, 9 Apr 2021 01:07:10 -0700 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Adrian Pop , "Michal Kubecek" CC: , Vladyslav Tarasiuk Subject: [PATCH net-next 7/8] phy: sfp: add netlink SFP support to generic SFP code Date: Fri, 9 Apr 2021 11:06:40 +0300 Message-ID: <1617955601-21055-8-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1617955601-21055-1-git-send-email-moshe@nvidia.com> References: <1617955601-21055-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 76507215-16d2-41f3-d345-08d8fb2e7b95 X-MS-TrafficTypeDiagnostic: DM6PR12MB4928: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tVXm5T9G3O1NVdFrvQyR5W6OVFQj2lQVWKv7zHNVpPzblXUzlyC79VQUle5nvS3lBzJPYTxX4AKGE4IGwrlE9+mDnowed3C/gqZ5ISg0iBRu1iINHN+3ofG6xRwbXW8M1OYfF2r0ZBtUt4nKBV+Nht+Se/BIe++4urHE6vFW91R/Q+/gG9sGc8LmgQRyF6x9WJ4kSmu5+8WatmIyA5DWKSRglsiFeI6RqT83If6MEPCDsDl2nhjiJWOHkVywKpvGRnzQ5ebEX67qN0SqxIB5hFCtzgKsqV6skl5eHiBiKvXizXnEeLgkt4eWkv90RkIaPmezKMAMrqNsYSoqnTUcnsU1amHRLySwoklL596L8mS0mAPafMltLer1hfvSv9CgvtwZFjPfm8AQCZVxM8ayP3h6G2r8BDTlK1tCAYLKfoC7cfUL2jGiMTrSY64GrMWfiGVuvyz6a513bllBdwqLzMRmi6gAxGOrCU4h6s4IFSGVJUJ12hq3Vm44nMpOYyIyRbcJwMKs4k+lfDI1dmIbH86W/BP0iyIRo5AfGBKqz9Az7ltIK/paNBK7AW8JX93A5Cgc2wO7aBZVdlQA/KmLXo9q5ddzB0xisVcBBApee+h1UopDBx5EqjceVeLXVV++QlTryiuzHQv+nNpLky75QWiV4CX/JAONCkysJ2j+kkpMaXn/o8TaD1O0XmEWkQpa 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)(346002)(396003)(136003)(376002)(46966006)(36840700001)(36756003)(26005)(82310400003)(186003)(86362001)(8676002)(478600001)(83380400001)(4326008)(54906003)(36860700001)(110136005)(8936002)(70206006)(6666004)(82740400003)(356005)(5660300002)(336012)(426003)(2906002)(7636003)(36906005)(7696005)(47076005)(107886003)(2616005)(70586007)(316002)(41533002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 08:07:13.1680 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 76507215-16d2-41f3-d345-08d8fb2e7b95 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: BN8NAM11FT026.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4928 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Andrew Lunn The new netlink API for reading SFP data requires a new op to be implemented. The idea of the new netlink SFP code is that userspace is responsible to parsing the EEPROM data and requesting pages, rather than have the kernel decide what pages are interesting and returning them. This allows greater flexibility for newer formats. Currently the generic SFP code only supports simple SFPs. Allow i2c address 0x50 and 0x51 to be accessed with page and bank must always be 0. This interface will later be extended when for example QSFP support is added. Signed-off-by: Andrew Lunn Signed-off-by: Vladyslav Tarasiuk --- drivers/net/phy/sfp-bus.c | 20 ++++++++++++++++++++ drivers/net/phy/sfp.c | 25 +++++++++++++++++++++++++ drivers/net/phy/sfp.h | 3 +++ include/linux/sfp.h | 10 ++++++++++ 4 files changed, 58 insertions(+) diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c index 2e11176c6b94..e61de66e973b 100644 --- a/drivers/net/phy/sfp-bus.c +++ b/drivers/net/phy/sfp-bus.c @@ -555,6 +555,26 @@ int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee, } EXPORT_SYMBOL_GPL(sfp_get_module_eeprom); +/** + * sfp_get_module_eeprom_by_page() - Read a page from the SFP module EEPROM + * @bus: a pointer to the &struct sfp_bus structure for the sfp module + * @page: a &struct ethtool_module_eeprom + * @extack: extack for reporting problems + * + * Read an EEPROM page as specified by the supplied @page. See the + * documentation for &struct ethtool_module_eeprom for the page to be read. + * + * Returns 0 on success or a negative errno number. More error + * information might be provided via extack + */ +int sfp_get_module_eeprom_by_page(struct sfp_bus *bus, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack) +{ + return bus->socket_ops->module_eeprom_by_page(bus->sfp, page, extack); +} +EXPORT_SYMBOL_GPL(sfp_get_module_eeprom_by_page); + /** * sfp_upstream_start() - Inform the SFP that the network device is up * @bus: a pointer to the &struct sfp_bus structure for the sfp module diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 7998acc689b7..37f722c763d7 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -2330,6 +2330,30 @@ static int sfp_module_eeprom(struct sfp *sfp, struct ethtool_eeprom *ee, return 0; } +static int sfp_module_eeprom_by_page(struct sfp *sfp, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack) +{ + if (page->bank) { + NL_SET_ERR_MSG(extack, "Banks not supported"); + return -EOPNOTSUPP; + } + + if (page->page) { + NL_SET_ERR_MSG(extack, "Only page 0 supported"); + return -EOPNOTSUPP; + } + + if (page->i2c_address != 0x50 && + page->i2c_address != 0x51) { + NL_SET_ERR_MSG(extack, "Only address 0x50 and 0x51 supported"); + return -EOPNOTSUPP; + } + + return sfp_read(sfp, page->i2c_address == 0x51, page->offset, + page->data, page->length); +}; + static const struct sfp_socket_ops sfp_module_ops = { .attach = sfp_attach, .detach = sfp_detach, @@ -2337,6 +2361,7 @@ static const struct sfp_socket_ops sfp_module_ops = { .stop = sfp_stop, .module_info = sfp_module_info, .module_eeprom = sfp_module_eeprom, + .module_eeprom_by_page = sfp_module_eeprom_by_page, }; static void sfp_timeout(struct work_struct *work) diff --git a/drivers/net/phy/sfp.h b/drivers/net/phy/sfp.h index b83f70526270..27226535c72b 100644 --- a/drivers/net/phy/sfp.h +++ b/drivers/net/phy/sfp.h @@ -14,6 +14,9 @@ struct sfp_socket_ops { int (*module_info)(struct sfp *sfp, struct ethtool_modinfo *modinfo); int (*module_eeprom)(struct sfp *sfp, struct ethtool_eeprom *ee, u8 *data); + int (*module_eeprom_by_page)(struct sfp *sfp, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack); }; int sfp_add_phy(struct sfp_bus *bus, struct phy_device *phydev); diff --git a/include/linux/sfp.h b/include/linux/sfp.h index 38893e4dd0f0..302094b855fb 100644 --- a/include/linux/sfp.h +++ b/include/linux/sfp.h @@ -542,6 +542,9 @@ phy_interface_t sfp_select_interface(struct sfp_bus *bus, int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo); int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee, u8 *data); +int sfp_get_module_eeprom_by_page(struct sfp_bus *bus, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack); void sfp_upstream_start(struct sfp_bus *bus); void sfp_upstream_stop(struct sfp_bus *bus); void sfp_bus_put(struct sfp_bus *bus); @@ -587,6 +590,13 @@ static inline int sfp_get_module_eeprom(struct sfp_bus *bus, return -EOPNOTSUPP; } +static inline int sfp_get_module_eeprom_by_page(struct sfp_bus *bus, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack) +{ + return -EOPNOTSUPP; +} + static inline void sfp_upstream_start(struct sfp_bus *bus) { } From patchwork Fri Apr 9 08:06: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: 12193273 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=-18.8 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, URIBL_BLOCKED,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 C0B4EC43460 for ; Fri, 9 Apr 2021 08:07:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8CEF561182 for ; Fri, 9 Apr 2021 08:07:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232452AbhDIIHe (ORCPT ); Fri, 9 Apr 2021 04:07:34 -0400 Received: from mail-mw2nam10on2083.outbound.protection.outlook.com ([40.107.94.83]:44896 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232631AbhDIIHa (ORCPT ); Fri, 9 Apr 2021 04:07:30 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G2pTniRqAMoqfUHzYyD3VgSYsMz887zUZPk+fH5/BcVPF32GNxRtuGKxlWef2QlHgq3pbXcFgl+ywXCaYXmpyXan7UaSq8kr2l9Y1K6ttjeRy2smpxnoiawg26KiwIdlVyZ53m6mKye25uexDISvxRfO0Kx9kjXNS94VNN8y/dg/syjGlS9Vo1fBfUK05NlrcnGeVFuLy2jAr3BoiS8b27CNKHLdUYD0xVmpMj6NFS52PYOxmXjvIRRwKJeTYqnh+wX6UPrMFeN+qfBM/yJfTtQ4soGYm1AC5apghlVNMFYyVDqZkKNNVpnctb8y2+JXVisHqmvtrXl9y8S2LgriPQ== 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=i66V+Wg2N7P6mO2v7VM+Q6/VZ15MMbVj5QOceB4ef9w=; b=noYpUWmid8GEHlT/1ppT0ADuC7DtLuZXbUkXHUVqPf8gpFuugADwjHlu5G2EbNp9u+YBiAzJEY4UtkKzuRgL0nOSAyd1PW9P414Z/47arRmepCsHzxGId4/Jn9luLeOF0KwnnwTtfD6K2cG89l5IZUwvlR5Qa/MkBjPYYV0T0fBEMF7kOU9Sc9iDC7lJNdAcVCE6TSCC6eBQ7LhuyVyf+ZNcucVejCblg/rosEQB1rKArMCBBAqewn9j1SwyS6c2OA7nwGO5o/QgZRWRy40vjo+smUc5+SiODaRrOgsnQfbfIEe5JPxz3lL0kNAAs5krbTfmHN+NUWIO6mDJWdC9Pg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=gmail.com 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=i66V+Wg2N7P6mO2v7VM+Q6/VZ15MMbVj5QOceB4ef9w=; b=oV4niLU06btupL3cqxRKVyNQZPFXVoOD8D6xRx8wiIPIBL6bvNNfRKOgJvLlHWkoFJQof9hMc3ePsdKEe/t3DwaV43czvdUSFD3MZAhT30ge6ne38O9ogEbavin8WyDUASBlEIrBCOapNf2IWQo8+TPslhXfH8foTrtKTq2utAxvDRHXUm+GWW+HBKB48SLeyioi59yKiVsUfla1UsAWFmz1UfwMFZSaHgrGcVCBIJW72/FVVBoJax6ATrSE8zlqOq097tDfxvQv9JisHUge9t+n0q4bDV5Ym/z0fH2VhBCAcKliS5hSmfezrrwNcWID/uE35KrA0sgtuoKIPvG9Nw== Received: from BN9PR03CA0064.namprd03.prod.outlook.com (2603:10b6:408:fc::9) by BL0PR12MB4708.namprd12.prod.outlook.com (2603:10b6:208:8d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Fri, 9 Apr 2021 08:07:16 +0000 Received: from BN8NAM11FT038.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fc:cafe::2) by BN9PR03CA0064.outlook.office365.com (2603:10b6:408:fc::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Fri, 9 Apr 2021 08:07:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT038.mail.protection.outlook.com (10.13.176.246) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4020.17 via Frontend Transport; Fri, 9 Apr 2021 08:07:16 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 9 Apr 2021 01:07:14 -0700 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; Fri, 9 Apr 2021 01:07:12 -0700 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Adrian Pop , "Michal Kubecek" CC: , Vladyslav Tarasiuk Subject: [PATCH net-next 8/8] ethtool: wire in generic SFP module access Date: Fri, 9 Apr 2021 11:06:41 +0300 Message-ID: <1617955601-21055-9-git-send-email-moshe@nvidia.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1617955601-21055-1-git-send-email-moshe@nvidia.com> References: <1617955601-21055-1-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f953365d-f544-46c2-defc-08d8fb2e7d8d X-MS-TrafficTypeDiagnostic: BL0PR12MB4708: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2512; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NDOco7Q4/JRlSFi7bsyC6al/4V9QQdwglL5CWFHonSd3IcXQAla4qdmylfproxzun64IIYTyroDif7gbgaPk+uWpXT8IeA8EMA78mSZJmrKg7QlufEXER8Htm8veQSD+legCCFFdwqiq011GsfeF8EbsBsp6Hq3dVIKpLMEN2Dd/bvF6O4jhbp7TMqEI20ECKXKpczUYjkXlMPUKp5oy0EsfpkKHFhp4jBsxxfirOg8AsUZtqMw3GkYlrpX6spX3cTyCV0ohiD65nsFuNkDSOYhsfpW9UJJ8mqJIEkxlneCXAAEZ1BB8ZZfUz3zbgoU7W5xCDLMgG7rGB+SKuX8dyrWGfhFqT72ml5FNwT4j3hz3bvv/TgH7XXCemATC7l0pty9sG8Vc3ZM7HnXjIqLGNjSUQG9vptVdKPueegq0HeAmR59ryQsJmYx5NN0NJnOvSSIE2i+yeWJDYAU3ojdfO6sTK19ccME6KFgkhfclw9Cra3pnTQc9sGgFinguhyvQufac8JrDEtRg5AacnrqYxwalucDeJ+3f8z19IxkgfhVdA33YMviXU0nGLz5MX8KC/ibJIkIrq8HAG5GeBtZ4bkT38SwRyWb/EP8MClPf/9bx4voi0vjvwFPKP/nePNBP+7DLj9RZ5BZJ3tOeI/MH8AyFwHpT2/BIa1FINMSd5AXisSdHIKrT6l3Rrzj+ToWN X-Forefront-Antispam-Report: CIP:216.228.112.32;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid01.nvidia.com;CAT:NONE;SFS:(4636009)(39860400002)(396003)(136003)(346002)(376002)(36840700001)(46966006)(336012)(7636003)(426003)(356005)(8936002)(316002)(82740400003)(26005)(107886003)(82310400003)(110136005)(86362001)(7696005)(2906002)(186003)(478600001)(2616005)(36756003)(83380400001)(4326008)(47076005)(36860700001)(70586007)(8676002)(6666004)(5660300002)(70206006)(54906003)(41533002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 08:07:16.4763 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f953365d-f544-46c2-defc-08d8fb2e7d8d 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.32];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT038.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4708 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Andrew Lunn If the device has a sfp bus attached, call its sfp_get_module_eeprom_by_page() function, otherwise use the ethtool op for the device. This follows how the IOCTL works. Signed-off-by: Andrew Lunn --- net/ethtool/eeprom.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/net/ethtool/eeprom.c b/net/ethtool/eeprom.c index 1a49c133d401..2a6733a6449a 100644 --- a/net/ethtool/eeprom.c +++ b/net/ethtool/eeprom.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only #include +#include #include "netlink.h" #include "common.h" @@ -85,6 +86,21 @@ static int eeprom_fallback(struct eeprom_req_info *request, return err; } +static int get_module_eeprom_by_page(struct net_device *dev, + struct ethtool_module_eeprom *page_data, + struct netlink_ext_ack *extack) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + + if (dev->sfp_bus) + return sfp_get_module_eeprom_by_page(dev->sfp_bus, page_data, extack); + + if (ops->get_module_info) + return ops->get_module_eeprom_by_page(dev, page_data, extack); + + return -EOPNOTSUPP; +} + static int eeprom_prepare_data(const struct ethnl_req_info *req_base, struct ethnl_reply_data *reply_base, struct genl_info *info) @@ -95,9 +111,6 @@ static int eeprom_prepare_data(const struct ethnl_req_info *req_base, struct net_device *dev = reply_base->dev; int ret; - if (!dev->ethtool_ops->get_module_eeprom_by_page) - return eeprom_fallback(request, reply, info); - page_data.offset = request->offset; page_data.length = request->length; page_data.i2c_address = request->i2c_address; @@ -111,8 +124,7 @@ static int eeprom_prepare_data(const struct ethnl_req_info *req_base, if (ret) goto err_free; - ret = dev->ethtool_ops->get_module_eeprom_by_page(dev, &page_data, - info->extack); + ret = get_module_eeprom_by_page(dev, &page_data, info->extack); if (ret < 0) goto err_ops; @@ -126,6 +138,9 @@ static int eeprom_prepare_data(const struct ethnl_req_info *req_base, ethnl_ops_complete(dev); err_free: kfree(page_data.data); + + if (ret == -EOPNOTSUPP) + return eeprom_fallback(request, reply, info); return ret; }