Message ID | 20230405153900.747-1-i.bornyakov@metrotek.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp444775vqo; Wed, 5 Apr 2023 09:41:27 -0700 (PDT) X-Google-Smtp-Source: AKy350bFawHmOMZqVF8Fun1WyjSq7NbBkny5kfLfy0Z7E+reyv+R7wpwjrBfKHzljMLXOwVDQDrZ X-Received: by 2002:a05:6a20:4f0f:b0:dd:cef1:93e4 with SMTP id gi15-20020a056a204f0f00b000ddcef193e4mr5570014pzb.14.1680712886758; Wed, 05 Apr 2023 09:41:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680712886; cv=none; d=google.com; s=arc-20160816; b=WMOmcVG1kyKwInfi0MmyRo14SkGdA+fmMRNxLYbFLo9C+i4PX4iKxYC4rWa0cIzEJt GplXVgztwBeRxgTEIrUokqtjEy2KZcfTedi9SeaWfGOUDQ8lWErPJUG3aWilwz8gP39a Zb8K9BgATjP4W/y3cSn8c3gFP6OBHGeHWTH0flLGc2fwoXs7I1AwQ6hjyXEc601ifMSp vTXNd0/TOWUFqi34ixsvoUo3QW6pATYiy6YZ2mONhTonMKOqGuVGgfxmSXp2yomrPJ32 OMX21N3QASjDkAmpA4RA6n/RpUm1gE6a8aLuevSoVGab+9VXRnN9MFhXOhPFnVVMgtM7 m3aw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Xzk8ovrE26io7MkHwjLg92Fn0UYh5nu3vjf1jI1mYqA=; b=nh0Xup8+rdCCNvUgAKSSkHlAItGGumTwSLrayNPNPXQ8Fv+ebSN1XCOW88YPOH6sKN LnQiS3e9BTHwkrsVdUdhDq7iuomV9nevOy9byxC/rJfONqf/I6cFFHb5gTAa6fQR5P2+ QdAJvmELE3/d4TXHn5WNdjTG7iF6Eu38kBG6KDCp1TeLJVmW+FBOvpCHzv9s+L4xIfjU zKZ2Wk1xobj/LBIawJlvpb+Ojjj8dKQOw4BGJW/ryfYFnSKcA33zWvZOIoEMCBRl12QJ 4GJLR0Y7F1GsZ/rvbKeikDW5VB/0f9fiOFhV1YlTeboU+gChLa/gvqG45BYWIuEIRvkk QyLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@metrotek.ru header.s=mail header.b=IIIgPy78; 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 138-20020a630090000000b005141972cc58si3766791pga.280.2023.04.05.09.41.14; Wed, 05 Apr 2023 09:41:26 -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=IIIgPy78; 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 S232750AbjDEQKI (ORCPT <rfc822;lkml4gm@gmail.com> + 99 others); Wed, 5 Apr 2023 12:10:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232321AbjDEQKC (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 5 Apr 2023 12:10:02 -0400 X-Greylist: delayed 1809 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 05 Apr 2023 09:09:53 PDT Received: from mail.pr-group.ru (mail.pr-group.ru [178.18.215.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 633AB10D8; Wed, 5 Apr 2023 09:09:53 -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; bh=HXWZ4XUXK8vGxYsn5UqljiIqwaTfxIUTeJ93pQO8yv0=; b=IIIgPy78rqr8S+tn6NsY2EvtjiKg+QIru842BL9PVeqTXvixeia2k4BeueSquX1gll0Q9MZpdk88P 9wkbyAQ1mY0IZkGHObVLjCDxKyE7uOzpGdB2pSKRCDOYCFGvVovxZWcN4ArP442YbUpgfeVmiZgjn6 B20s8KSfb8FdJPDiJH0tKbq49wMSRWpt80EPNpGf+X4KkLabY1WBNdnxVskiRdlaCt6DnsmmRuDGsf +Bsn+BZ4Oi5m29jHnE0Tb4cZ5ePwG0kTPm6mPj6COz5OP4QkkVKWh5Yt+k2ftvJ7LpLGJpfhcER6pZ 58bgnFiOYPt+OvgZ2Ma8q0cwx1dtlNw== X-Kerio-Anti-Spam: Build: [Engines: 2.17.2.1477, Stamp: 3], Multi: [Enabled, t: (0.000012,0.013713)], BW: [Enabled, t: (0.000025,0.000001)], RTDA: [Enabled, t: (0.090298), Hit: No, Details: v2.49.0; Id: 15.4d9lk.1gt9153nq.b2hs; 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)); Wed, 5 Apr 2023 18:39:18 +0300 From: Ivan Bornyakov <i.bornyakov@metrotek.ru> To: netdev@vger.kernel.org Cc: Ivan Bornyakov <i.bornyakov@metrotek.ru>, 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] net: sfp: initialize sfp->i2c_block_size at sfp allocation Date: Wed, 5 Apr 2023 18:39:00 +0300 Message-Id: <20230405153900.747-1-i.bornyakov@metrotek.ru> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762355195607518059?= X-GMAIL-MSGID: =?utf-8?q?1762355195607518059?= |
Series |
[net] net: sfp: initialize sfp->i2c_block_size at sfp allocation
|
|
Commit Message
Ivan Bornyakov
April 5, 2023, 3:39 p.m. UTC
sfp->i2c_block_size is initialized at SFP module insertion in
sfp_sm_mod_probe(). Because of that, if SFP module was not inserted
since boot, ethtool -m leads to 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 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 ethtool -m with SFP module removed will fail the same way, i.e.
-EREMOTEIO, in both cases and without errors from I2C adapter.
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Fixes: 0d035bed2a4a ("net: sfp: VSOL V2801F / CarlitoxxPro CPGOS03-0490 v2.0 workaround")
Cc: stable@vger.kernel.org
---
drivers/net/phy/sfp.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
Comments
On Wed, Apr 05, 2023 at 06:39:00PM +0300, Ivan Bornyakov wrote: > sfp->i2c_block_size is initialized at SFP module insertion in > sfp_sm_mod_probe(). Because of that, if SFP module was not inserted > since boot, ethtool -m leads to 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 Do i understand you correct in that this is when the SFP cage has always been empty? The I2C transaction is going to fail whatever the length is. > If SFP module was plugged then removed at least once, > sfp->i2c_block_size will be initialized and ethtool -m will fail with > different error > > # ethtool -m xge0 > Cannot get Module EEPROM data: Remote I/O error So again, the SFP cage is empty? I wonder if a better fix is to use sfp->state & SFP_F_PRESENT in sfp_module_eeprom() and sfp_module_eeprom_by_page() and don't even do the I2C read if there is no module in the cage? Andrew
On Wed, Apr 05, 2023 at 09:35:31PM +0200, Andrew Lunn wrote: > On Wed, Apr 05, 2023 at 06:39:00PM +0300, Ivan Bornyakov wrote: > > sfp->i2c_block_size is initialized at SFP module insertion in > > sfp_sm_mod_probe(). Because of that, if SFP module was not inserted > > since boot, ethtool -m leads to 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 > > Do i understand you correct in that this is when the SFP cage has > always been empty? The I2C transaction is going to fail whatever the > length is. > Yes, SFP cage is empty, I2C transaction will fail anyways, but not all I2C controllers are happy about zero-length reads. > > If SFP module was plugged then removed at least once, > > sfp->i2c_block_size will be initialized and ethtool -m will fail with > > different error > > > > # ethtool -m xge0 > > Cannot get Module EEPROM data: Remote I/O error > > So again, the SFP cage is empty? > > I wonder if a better fix is to use > > sfp->state & SFP_F_PRESENT > > in sfp_module_eeprom() and sfp_module_eeprom_by_page() and don't even > do the I2C read if there is no module in the cage? > This is also worthy addition to sfp.c, but IMHO sfp->i2c_block_size initialization still need to be fixed since $ grep -c "sfp_read(" drivers/net/phy/sfp.c 31 and I can't vouch all of them are possible only after SFP module insertion. Also for future proof reason.
On Wed, Apr 05, 2023 at 11:41:16PM +0300, Ivan Bornyakov wrote: > On Wed, Apr 05, 2023 at 09:35:31PM +0200, Andrew Lunn wrote: > > On Wed, Apr 05, 2023 at 06:39:00PM +0300, Ivan Bornyakov wrote: > > > sfp->i2c_block_size is initialized at SFP module insertion in > > > sfp_sm_mod_probe(). Because of that, if SFP module was not inserted > > > since boot, ethtool -m leads to 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 > > > > Do i understand you correct in that this is when the SFP cage has > > always been empty? The I2C transaction is going to fail whatever the > > length is. > > > > Yes, SFP cage is empty, I2C transaction will fail anyways, but not all > I2C controllers are happy about zero-length reads. > > > > If SFP module was plugged then removed at least once, > > > sfp->i2c_block_size will be initialized and ethtool -m will fail with > > > different error > > > > > > # ethtool -m xge0 > > > Cannot get Module EEPROM data: Remote I/O error > > > > So again, the SFP cage is empty? > > > > I wonder if a better fix is to use > > > > sfp->state & SFP_F_PRESENT > > > > in sfp_module_eeprom() and sfp_module_eeprom_by_page() and don't even > > do the I2C read if there is no module in the cage? > > > > This is also worthy addition to sfp.c, but IMHO sfp->i2c_block_size > initialization still need to be fixed since > > $ grep -c "sfp_read(" drivers/net/phy/sfp.c > 31 > > and I can't vouch all of them are possible only after SFP module > insertion. Also for future proof reason. I think everything else should be safe. A lot of those reads are for the HWMON code. And the HWMON code only registers when the module is inserted. How about two patches, what you have here, plus checking sfp->state & SFP_F_PRESENT in the ethtool functions? Andrew
On Wed, Apr 05, 2023 at 10:51:38PM +0200, Andrew Lunn wrote: > On Wed, Apr 05, 2023 at 11:41:16PM +0300, Ivan Bornyakov wrote: > > On Wed, Apr 05, 2023 at 09:35:31PM +0200, Andrew Lunn wrote: > > > On Wed, Apr 05, 2023 at 06:39:00PM +0300, Ivan Bornyakov wrote: > > > > sfp->i2c_block_size is initialized at SFP module insertion in > > > > sfp_sm_mod_probe(). Because of that, if SFP module was not inserted > > > > since boot, ethtool -m leads to 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 > > > > > > Do i understand you correct in that this is when the SFP cage has > > > always been empty? The I2C transaction is going to fail whatever the > > > length is. > > > > > > > Yes, SFP cage is empty, I2C transaction will fail anyways, but not all > > I2C controllers are happy about zero-length reads. > > > > > > If SFP module was plugged then removed at least once, > > > > sfp->i2c_block_size will be initialized and ethtool -m will fail with > > > > different error > > > > > > > > # ethtool -m xge0 > > > > Cannot get Module EEPROM data: Remote I/O error > > > > > > So again, the SFP cage is empty? > > > > > > I wonder if a better fix is to use > > > > > > sfp->state & SFP_F_PRESENT > > > > > > in sfp_module_eeprom() and sfp_module_eeprom_by_page() and don't even > > > do the I2C read if there is no module in the cage? > > > > > > > This is also worthy addition to sfp.c, but IMHO sfp->i2c_block_size > > initialization still need to be fixed since > > > > $ grep -c "sfp_read(" drivers/net/phy/sfp.c > > 31 > > > > and I can't vouch all of them are possible only after SFP module > > insertion. Also for future proof reason. > > I think everything else should be safe. A lot of those reads are for > the HWMON code. And the HWMON code only registers when the module is > inserted. > > How about two patches, what you have here, plus checking sfp->state & > SFP_F_PRESENT in the ethtool functions? > > Andrew Sure, will do in the near future.
On Wed, 5 Apr 2023 18:39:00 +0300 Ivan Bornyakov wrote: > sfp->i2c_block_size is initialized at SFP module insertion in > sfp_sm_mod_probe(). Because of that, if SFP module was not inserted > since boot, ethtool -m leads to 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 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 ethtool -m with SFP module removed will fail the same way, i.e. > -EREMOTEIO, in both cases and without errors from I2C adapter. Hi Russell - yes / no / come back when both patches are ready?
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);