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 <[email protected]>
---
 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 via email to