From patchwork Thu Apr 6 13:08:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Bornyakov X-Patchwork-Id: 80242 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1029342vqo; Thu, 6 Apr 2023 06:32:50 -0700 (PDT) X-Google-Smtp-Source: AKy350YrCHcKkOaa6sGNMOoLjPl+eLZq3EQe/06f/PffNeC0byWUF+PhOKAQJ6zTk1kNEkVrutR2 X-Received: by 2002:a05:6a20:4c90:b0:d0:4361:9723 with SMTP id fq16-20020a056a204c9000b000d043619723mr3205351pzb.22.1680787970378; Thu, 06 Apr 2023 06:32:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680787970; cv=none; d=google.com; s=arc-20160816; b=soaw9vp1PQSj8lOotcvUoWoUYf0M2ovWdcZYzcys+GDcZYM+cAkfUhmV4cPhIdAmOE K9RmdlKux+FFqrtSdgL+TG7Dv+EinOUjfWjeV82JnygI4GE6wpbEqlbId+S48uMginmT tLnTWn5pk9M7rHZ3D0jPRFvIk0fbp0XDI0mR4cN3DIECJD/C9TbV9gDlPL6nuxSGXBDX BxFT8pRwH62cDWldxNQx86w5Ds7a4IFVRGxBIeB8kdNW3DJPmExSazP2kFGHdXZcX3cW A0wyWfeSFv8MZaiXHu3Bd8qFIKcuVg9UTSHSKSSb0Ma+Wcc5cVqxzVrK27fq36z9P2o8 bfNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=u67nvy1TmEKGe7cd5Kov90Q0EanOeViAiHHRRl+9uzc=; b=yLMWRsIvbtlkeEJPAaQEX/dDipk8zrtLQT1xCM4xCXv82FKCRVhn9Mof1Qw78niPJL cglq4q35z2EdRxdYDQ7GZEaoZjaiJRYP1hA1csyLHznfskdrSq/Ndb4GCJSjmE6XUYf8 JJJoEUq7tnYPjAXm/8K1CydTlIVCvU1CZhavSS9Qs/QTKl3OhsgiS3o55vbXuxX7+j7k CLlqrhyFA/5npL9ZWxNWj8UUC5+qMZhvnBG71zLW6Yy9YWAauG/qK1Tqn1s/zdzKweUY fuQi7pJiE/VF8YumN8+bQP8wnZNQQFyiaD3B48EbuRYfWS4lssFpdCfELrnVRSV6LliS +WJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@metrotek.ru header.s=mail header.b=OqltBQhy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b34-20020a631b62000000b0051367d909efsi1269622pgm.106.2023.04.06.06.32.36; Thu, 06 Apr 2023 06:32:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@metrotek.ru header.s=mail header.b=OqltBQhy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237993AbjDFNJc (ORCPT + 99 others); Thu, 6 Apr 2023 09:09:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236370AbjDFNJY (ORCPT ); Thu, 6 Apr 2023 09:09:24 -0400 Received: from mail.pr-group.ru (mail.pr-group.ru [178.18.215.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF966191; Thu, 6 Apr 2023 06:09:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=metrotek.ru; s=mail; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding: in-reply-to:references; bh=IO1EPmwiDtC2Abwn+uXaFr8L4ym/D/q1VCAduJB0S5E=; b=OqltBQhyEToBbHc0pbG9rU+aQL2jXagCBFKlbuLlIaYcVVsw4bEx8zc+LE0uxjCLrcPAMLIuDxYZp fSKKeUcIZLVgPHaLJqHwANV4WmXeBt9im0Wifc4gm/IJyzsRHWVgsendPWpfDEt6220AB/fOnK+TQ6 CWqQ4w5Vw2agZ3COwJ2RORYCvF3d7pxQgz/juVenZrp3Q+7/6M2duggyILwr29Rm4SHvSCTan6TLF2 2VUV1h3zHMRq10Wae0ssb/1KV1zsxFo5EcAR/R+jK7tOG1nHJriXsvHSHTyFkvxKMWs8WmPmjUSYzI kSM8+WCK7G8iDy0inrrTzbqVF7iULVQ== X-Kerio-Anti-Spam: Build: [Engines: 2.17.2.1477, Stamp: 3], Multi: [Enabled, t: (0.000006,0.014053)], BW: [Enabled, t: (0.000028,0.000001)], RTDA: [Enabled, t: (0.103778), Hit: No, Details: v2.49.0; Id: 15.8wv4b.1gtbaumsr.6g4f; mclb], total: 0(700) X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Level: X-Footer: bWV0cm90ZWsucnU= Received: from localhost.localdomain ([78.37.166.219]) (authenticated user i.bornyakov@metrotek.ru) by mail.pr-group.ru with ESMTPSA (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)); Thu, 6 Apr 2023 16:09:02 +0300 From: Ivan Bornyakov To: netdev@vger.kernel.org Cc: Ivan Bornyakov , linux@armlinux.org.uk, andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, system@metrotek.ru, stable@vger.kernel.org Subject: [PATCH net v2 1/2] net: sfp: initialize sfp->i2c_block_size at sfp allocation Date: Thu, 6 Apr 2023 16:08:32 +0300 Message-Id: <20230406130833.32160-2-i.bornyakov@metrotek.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230406130833.32160-1-i.bornyakov@metrotek.ru> References: <20230406130833.32160-1-i.bornyakov@metrotek.ru> MIME-Version: 1.0 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762433926619902496?= X-GMAIL-MSGID: =?utf-8?q?1762433926619902496?= sfp->i2c_block_size is initialized at SFP module insertion in sfp_sm_mod_probe(). Because of that, if SFP module was never inserted since boot, sfp_read() call will lead to zero-length I2C read attempt, and not all I2C controllers are happy with zero-length reads. One way to issue sfp_read() on empty SFP cage is to execute ethtool -m. If SFP module was never plugged since boot, there will be a zero-length I2C read attempt. # ethtool -m xge0 i2c i2c-3: adapter quirk: no zero length (addr 0x0050, size 0, read) Cannot get Module EEPROM data: Operation not supported If SFP module was plugged then removed at least once, sfp->i2c_block_size will be initialized and ethtool -m will fail with different exit code and without I2C error # ethtool -m xge0 Cannot get Module EEPROM data: Remote I/O error Fix this by initializing sfp->i2_block_size at struct sfp allocation stage so no wild sfp_read() could issue zero-length I2C read. Signed-off-by: Ivan Bornyakov Fixes: 0d035bed2a4a ("net: sfp: VSOL V2801F / CarlitoxxPro CPGOS03-0490 v2.0 workaround") Cc: stable@vger.kernel.org Reviewed-by: Andrew Lunn --- drivers/net/phy/sfp.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 40c9a64c5e30..5663a184644d 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -212,6 +212,12 @@ static const enum gpiod_flags gpio_flags[] = { #define SFP_PHY_ADDR 22 #define SFP_PHY_ADDR_ROLLBALL 17 +/* SFP_EEPROM_BLOCK_SIZE is the size of data chunk to read the EEPROM + * at a time. Some SFP modules and also some Linux I2C drivers do not like + * reads longer than 16 bytes. + */ +#define SFP_EEPROM_BLOCK_SIZE 16 + struct sff_data { unsigned int gpios; bool (*module_supported)(const struct sfp_eeprom_id *id); @@ -1928,11 +1934,7 @@ static int sfp_sm_mod_probe(struct sfp *sfp, bool report) u8 check; int ret; - /* Some SFP modules and also some Linux I2C drivers do not like reads - * longer than 16 bytes, so read the EEPROM in chunks of 16 bytes at - * a time. - */ - sfp->i2c_block_size = 16; + sfp->i2c_block_size = SFP_EEPROM_BLOCK_SIZE; ret = sfp_read(sfp, false, 0, &id.base, sizeof(id.base)); if (ret < 0) { @@ -2615,6 +2617,7 @@ static struct sfp *sfp_alloc(struct device *dev) return ERR_PTR(-ENOMEM); sfp->dev = dev; + sfp->i2c_block_size = SFP_EEPROM_BLOCK_SIZE; mutex_init(&sfp->sm_mutex); mutex_init(&sfp->st_mutex); From patchwork Thu Apr 6 13:08:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Bornyakov X-Patchwork-Id: 80240 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1028388vqo; Thu, 6 Apr 2023 06:31:41 -0700 (PDT) X-Google-Smtp-Source: AKy350YQV3IFPufoiB02JEJITw8W2oz9IYhmJjAxt+YcrMFk2R+nHaVVPWDuctDw3VufzM6ILQpF X-Received: by 2002:a17:907:6a17:b0:932:217c:b85d with SMTP id rf23-20020a1709076a1700b00932217cb85dmr6517567ejc.37.1680787901005; Thu, 06 Apr 2023 06:31:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680787900; cv=none; d=google.com; s=arc-20160816; b=qEXsKv/AGAEBo6P7PfNoBivZzy/Pa9t4cTzmYvQJpqbAGYITd8v7bi1n5FgG+/m8FS +0KOc1idQUr0nxHwprrXykz4aOEU3Bi4M08s2u91lTHg909qZANdQjb0SmBAcKW59Vbg WGPNTzAM2VPFiJvL84VGWs8kd6NDgzL7DGkJJA/Nt4eHFZYMCDMKOhnjRtkbcyUyoD4w FLC+yHRZfBIojCXBE/03U4uK0oDdKLI2ec7ZqMmTpnGoC5S9foSY1O6WeCpNuLCpiLbb FYFhwvjsNtxbIbeU492uYE+taK4zr5UqL6fw+AS/wGYmoIAoaqAvz7heXrQqfA7AuIFS Pbkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m5NQDUsqoUM/Y5Sd7PwKjBmYeQjf7Mk8AzSu7kL73pw=; b=TK8edwqWLshOK/pctm1YFdZNxGRC07/1I1cD7XTIhbsWkale2rJofopVRfX0ZEXiBT 3bdtln2j8wRfiYnelC3ZALdUxMXYo1MumHyIImciZb7TiUSgw6g0oYUAeozbekQEX5fo q33IyZP+foWtGgj3jBMt6ng0+s+dF1lU+HWsmLZH8+r3CRoxq2/pBXdwdyIy2XJiEV+M /7++j/mqfrM1zc6pLAUHW3g1UOORw9IM8K9PdcWscjk0ZBLsin3OLtzRoyUSFmj7LT3L XNKaqLTvhu02drkCAF3sQzuRixXX76r+blkFugA0dNtm4SZEdqCCVrCGTuOQrPhQD5i/ SvyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@metrotek.ru header.s=mail header.b=KT8hnRtr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020a1709062dc200b009444a1ca923si1078085eji.262.2023.04.06.06.31.16; Thu, 06 Apr 2023 06:31:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@metrotek.ru header.s=mail header.b=KT8hnRtr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236672AbjDFNJg (ORCPT + 99 others); Thu, 6 Apr 2023 09:09:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237027AbjDFNJY (ORCPT ); Thu, 6 Apr 2023 09:09:24 -0400 Received: from mail.pr-group.ru (mail.pr-group.ru [178.18.215.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F0B949D1; Thu, 6 Apr 2023 06:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=metrotek.ru; s=mail; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding: in-reply-to:references; bh=P5ACJ2S+rz/slua9T/dUeE+wX3wCOdG0OX28eLza1E0=; b=KT8hnRtrvRGnzG8wqYeiM8eiR9ReCj7oNBjNwd6W5jwHiYHa0ULrAjpTJ/s7t6AQCK+LnUbzC0YGN QuBLy4ZsxziUYs36m+DGCT1gs9tG6U+zv6X7GoUE2nCUCOUXnC/A76ZLzBVYDvN6bF0X2e72U3T2WP w3DogZ9ZcdIPLfg+ehBT08qOUQvnA9PJGDLhGLYql2aOHIkE5/9w6kvTFEn3KCfPJxnImx5xfj3yXJ l9aAIY47V8knQyx3xtdHgx89EycX15GkXMFuGoSmxEm7DLzkNbYK9EPCQNX1dPAzTbd61dCEELuflM L90fMNnb6yCcvn3xYPM5ZHQjuHG32pQ== X-Kerio-Anti-Spam: Build: [Engines: 2.17.2.1477, Stamp: 3], Multi: [Enabled, t: (0.000012,0.007277)], BW: [Enabled, t: (0.000028,0.000001)], RTDA: [Enabled, t: (0.123683), Hit: No, Details: v2.49.0; Id: 15.csws6.1gtbauqpq.6o3; mclb], total: 0(700) X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Level: X-Footer: bWV0cm90ZWsucnU= Received: from localhost.localdomain ([78.37.166.219]) (authenticated user i.bornyakov@metrotek.ru) by mail.pr-group.ru with ESMTPSA (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)); Thu, 6 Apr 2023 16:09:06 +0300 From: Ivan Bornyakov To: netdev@vger.kernel.org Cc: Ivan Bornyakov , linux@armlinux.org.uk, andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, system@metrotek.ru Subject: [PATCH net v2 2/2] net: sfp: avoid EEPROM read of absent SFP module Date: Thu, 6 Apr 2023 16:08:33 +0300 Message-Id: <20230406130833.32160-3-i.bornyakov@metrotek.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230406130833.32160-1-i.bornyakov@metrotek.ru> References: <20230406130833.32160-1-i.bornyakov@metrotek.ru> MIME-Version: 1.0 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762433854331695473?= X-GMAIL-MSGID: =?utf-8?q?1762433854331695473?= If SFP module is not present, it is sensible to fail sfp_module_eeprom() and sfp_module_eeprom_by_page() early to avoid excessive I2C transfers which are garanteed to fail. Suggested-by: Andrew Lunn Signed-off-by: Ivan Bornyakov Reviewed-by: Andrew Lunn --- drivers/net/phy/sfp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 5663a184644d..6f32c2ab415d 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -2481,6 +2481,9 @@ static int sfp_module_eeprom(struct sfp *sfp, struct ethtool_eeprom *ee, unsigned int first, last, len; int ret; + if (!(sfp->state & SFP_F_PRESENT)) + return -ENODEV; + if (ee->len == 0) return -EINVAL; @@ -2513,6 +2516,9 @@ static int sfp_module_eeprom_by_page(struct sfp *sfp, const struct ethtool_module_eeprom *page, struct netlink_ext_ack *extack) { + if (!(sfp->state & SFP_F_PRESENT)) + return -ENODEV; + if (page->bank) { NL_SET_ERR_MSG(extack, "Banks not supported"); return -EOPNOTSUPP;