Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next 2/2] igb: read SFP module EEPROM through igb_read_sfp_data_byte
@ 2026-07-18 16:56 Pawel Dembicki
  0 siblings, 0 replies; only message in thread
From: Pawel Dembicki @ 2026-07-18 16:56 UTC (permalink / raw)
  To: netdev
  Cc: Pawel Dembicki, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	intel-wired-lan, linux-kernel

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-18 16:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-18 16:56 [PATCH net-next 2/2] igb: read SFP module EEPROM through igb_read_sfp_data_byte Pawel Dembicki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox