Skip to content

Commit 4400081

Browse files
Arkadi Sharshevskydavem330
authored andcommitted
mlxsw: spectrum: Fix EEPROM access in case of SFP/SFP+
The current code does not handle correctly the access to the upper page in case of SFP/SFP+ EEPROM. In that case the offset should be local and the I2C address should be changed. Fixes: 2ea1090 ("mlxsw: spectrum: Add support for access cable info via ethtool") Reported-by: Florian Klink <[email protected]> Signed-off-by: Arkadi Sharshevsky <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1f4f554 commit 4400081

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,9 @@ static int mlxsw_sp_flash_device(struct net_device *dev,
25452545
return err;
25462546
}
25472547

2548-
#define MLXSW_SP_QSFP_I2C_ADDR 0x50
2548+
#define MLXSW_SP_I2C_ADDR_LOW 0x50
2549+
#define MLXSW_SP_I2C_ADDR_HIGH 0x51
2550+
#define MLXSW_SP_EEPROM_PAGE_LENGTH 256
25492551

25502552
static int mlxsw_sp_query_module_eeprom(struct mlxsw_sp_port *mlxsw_sp_port,
25512553
u16 offset, u16 size, void *data,
@@ -2554,12 +2556,25 @@ static int mlxsw_sp_query_module_eeprom(struct mlxsw_sp_port *mlxsw_sp_port,
25542556
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
25552557
char eeprom_tmp[MLXSW_SP_REG_MCIA_EEPROM_SIZE];
25562558
char mcia_pl[MLXSW_REG_MCIA_LEN];
2559+
u16 i2c_addr;
25572560
int status;
25582561
int err;
25592562

25602563
size = min_t(u16, size, MLXSW_SP_REG_MCIA_EEPROM_SIZE);
2564+
2565+
if (offset < MLXSW_SP_EEPROM_PAGE_LENGTH &&
2566+
offset + size > MLXSW_SP_EEPROM_PAGE_LENGTH)
2567+
/* Cross pages read, read until offset 256 in low page */
2568+
size = MLXSW_SP_EEPROM_PAGE_LENGTH - offset;
2569+
2570+
i2c_addr = MLXSW_SP_I2C_ADDR_LOW;
2571+
if (offset >= MLXSW_SP_EEPROM_PAGE_LENGTH) {
2572+
i2c_addr = MLXSW_SP_I2C_ADDR_HIGH;
2573+
offset -= MLXSW_SP_EEPROM_PAGE_LENGTH;
2574+
}
2575+
25612576
mlxsw_reg_mcia_pack(mcia_pl, mlxsw_sp_port->mapping.module,
2562-
0, 0, offset, size, MLXSW_SP_QSFP_I2C_ADDR);
2577+
0, 0, offset, size, i2c_addr);
25632578

25642579
err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(mcia), mcia_pl);
25652580
if (err)

0 commit comments

Comments
 (0)