Netdev List
 help / color / mirror / Atom feed
From: Pawel Dembicki <paweldembicki@gmail.com>
To: netdev@vger.kernel.org
Cc: Pawel Dembicki <paweldembicki@gmail.com>,
	Tony Nguyen <anthony.l.nguyen@intel.com>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next 2/2] igb: read SFP module EEPROM through igb_read_sfp_data_byte
Date: Sat, 18 Jul 2026 18:56:25 +0200	[thread overview]
Message-ID: <20260718165637.3621784-2-paweldembicki@gmail.com> (raw)

igb_get_module_info() and igb_get_module_eeprom() use
igb_read_phy_reg_i2c(), which accesses the external PHY register space.
On designs with an external SGMII PHY this returns PHY register contents
instead of the SFP module EEPROM requested by ethtool -m.

Use igb_read_sfp_data_byte() for module EEPROM reads. The legacy
ethtool module EEPROM offset space maps directly to the I210 I2CCMD
module address space: offsets 0x000-0x0ff address the SFP base EEPROM
and offsets 0x100-0x1ff address the diagnostics EEPROM.

Assisted-by: Codex:GPT-5
Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
---
 drivers/net/ethernet/intel/igb/igb_ethtool.c | 40 ++++++--------------
 1 file changed, 12 insertions(+), 28 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
index 65014a54a6d1..0fb15bd940d7 100644
--- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
+++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
@@ -3209,7 +3209,7 @@ static int igb_get_module_info(struct net_device *netdev,
 	struct igb_adapter *adapter = netdev_priv(netdev);
 	struct e1000_hw *hw = &adapter->hw;
 	u32 status = 0;
-	u16 sff8472_rev, addr_mode;
+	u8 sff8472_rev, addr_mode;
 	bool page_swap = false;
 
 	if ((hw->phy.media_type == e1000_media_type_copper) ||
@@ -3217,22 +3217,26 @@ static int igb_get_module_info(struct net_device *netdev,
 		return -EOPNOTSUPP;
 
 	/* Check whether we support SFF-8472 or not */
-	status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_COMP, &sff8472_rev);
+	status = igb_read_sfp_data_byte(hw,
+					E1000_I2CCMD_SFP_DATA_ADDR(IGB_SFF_8472_COMP),
+					&sff8472_rev);
 	if (status)
 		return -EIO;
 
 	/* addressing mode is not supported */
-	status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_SWAP, &addr_mode);
+	status = igb_read_sfp_data_byte(hw,
+					E1000_I2CCMD_SFP_DATA_ADDR(IGB_SFF_8472_SWAP),
+					&addr_mode);
 	if (status)
 		return -EIO;
 
 	/* addressing mode is not supported */
-	if ((addr_mode & 0xFF) & IGB_SFF_ADDRESSING_MODE) {
+	if (addr_mode & IGB_SFF_ADDRESSING_MODE) {
 		hw_dbg("Address change required to access page 0xA2, but not supported. Please report the module type to the driver maintainers.\n");
 		page_swap = true;
 	}
 
-	if ((sff8472_rev & 0xFF) == IGB_SFF_8472_UNSUP || page_swap) {
+	if (sff8472_rev == IGB_SFF_8472_UNSUP || page_swap) {
 		/* We have an SFP, but it does not support SFF-8472 */
 		modinfo->type = ETH_MODULE_SFF_8079;
 		modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
@@ -3251,37 +3255,17 @@ static int igb_get_module_eeprom(struct net_device *netdev,
 	struct igb_adapter *adapter = netdev_priv(netdev);
 	struct e1000_hw *hw = &adapter->hw;
 	u32 status = 0;
-	u16 *dataword;
-	u16 first_word, last_word;
 	int i = 0;
 
 	if (ee->len == 0)
 		return -EINVAL;
 
-	first_word = ee->offset >> 1;
-	last_word = (ee->offset + ee->len - 1) >> 1;
-
-	dataword = kmalloc_array(last_word - first_word + 1, sizeof(u16),
-				 GFP_KERNEL);
-	if (!dataword)
-		return -ENOMEM;
-
-	/* Read EEPROM block, SFF-8079/SFF-8472, word at a time */
-	for (i = 0; i < last_word - first_word + 1; i++) {
-		status = igb_read_phy_reg_i2c(hw, (first_word + i) * 2,
-					      &dataword[i]);
-		if (status) {
-			/* Error occurred while reading module */
-			kfree(dataword);
+	for (i = 0; i < ee->len; i++) {
+		status = igb_read_sfp_data_byte(hw, ee->offset + i, &data[i]);
+		if (status)
 			return -EIO;
-		}
-
-		be16_to_cpus(&dataword[i]);
 	}
 
-	memcpy(data, (u8 *)dataword + (ee->offset & 1), ee->len);
-	kfree(dataword);
-
 	return 0;
 }
 
-- 
2.43.0


                 reply	other threads:[~2026-07-18 16:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260718165637.3621784-2-paweldembicki@gmail.com \
    --to=paweldembicki@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox