Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp907680rwl; Wed, 5 Apr 2023 09:12:11 -0700 (PDT) X-Google-Smtp-Source: AKy350brpJE99bwZvNK3+XkYTtvSlclmlVFLSQUcDXw9jCrNrYuPsFmH8dtic2tOPDcT+yfD4axN X-Received: by 2002:a05:6a20:2921:b0:cc:ca9:4fde with SMTP id t33-20020a056a20292100b000cc0ca94fdemr5193535pzf.33.1680711131244; Wed, 05 Apr 2023 09:12:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680711131; cv=none; d=google.com; s=arc-20160816; b=ubI5JBYLhj9XZX8d2jIJBRPl6BH/amOi818r4D3ZSt8Q5rJDxOypoTeQvm5iSzUoJU M19HboUShWRl3RKPES1fkaqwmh1wTy9Ky39Bq14YJ6GcUey9RFfJitWCu0UaqlA3Eymh sycd/I75t08h3a2oFKwHrjxLjSumks4eqdIXl8fW0hQbPuDZCJCQ4SZ3zCAnj33U25JW KZc3AuH8SUi1ptVEKOpwvf5ySevQlepO+I/TfsQ6ICtoT6gQuzV8q/r5MUG+lLfyEDo/ mxSlNL34fB4IS86aG9sKZNhxOgiwy5HThY3SPaFURdBmOdfAd4D6LbXO3hPw6y/rHpSC HktQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o8-20020aa79788000000b0062d90384500si12852651pfp.307.2023.04.05.09.11.56; Wed, 05 Apr 2023 09:12:11 -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 S233385AbjDEQKI (ORCPT + 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 ); 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 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] 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 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(-) 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); -- 2.39.2