Commit 4400081b authored by Arkadi Sharshevsky's avatar Arkadi Sharshevsky Committed by David S. Miller

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: 2ea10903 ("mlxsw: spectrum: Add support for access cable info via ethtool")
Reported-by: default avatarFlorian Klink <flokli@flokli.de>
Signed-off-by: default avatarArkadi Sharshevsky <arkadis@mellanox.com>
Reviewed-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1f4f554a
...@@ -2545,7 +2545,9 @@ static int mlxsw_sp_flash_device(struct net_device *dev, ...@@ -2545,7 +2545,9 @@ static int mlxsw_sp_flash_device(struct net_device *dev,
return err; return err;
} }
#define MLXSW_SP_QSFP_I2C_ADDR 0x50 #define MLXSW_SP_I2C_ADDR_LOW 0x50
#define MLXSW_SP_I2C_ADDR_HIGH 0x51
#define MLXSW_SP_EEPROM_PAGE_LENGTH 256
static int mlxsw_sp_query_module_eeprom(struct mlxsw_sp_port *mlxsw_sp_port, static int mlxsw_sp_query_module_eeprom(struct mlxsw_sp_port *mlxsw_sp_port,
u16 offset, u16 size, void *data, u16 offset, u16 size, void *data,
...@@ -2554,12 +2556,25 @@ static int mlxsw_sp_query_module_eeprom(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -2554,12 +2556,25 @@ static int mlxsw_sp_query_module_eeprom(struct mlxsw_sp_port *mlxsw_sp_port,
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
char eeprom_tmp[MLXSW_SP_REG_MCIA_EEPROM_SIZE]; char eeprom_tmp[MLXSW_SP_REG_MCIA_EEPROM_SIZE];
char mcia_pl[MLXSW_REG_MCIA_LEN]; char mcia_pl[MLXSW_REG_MCIA_LEN];
u16 i2c_addr;
int status; int status;
int err; int err;
size = min_t(u16, size, MLXSW_SP_REG_MCIA_EEPROM_SIZE); size = min_t(u16, size, MLXSW_SP_REG_MCIA_EEPROM_SIZE);
if (offset < MLXSW_SP_EEPROM_PAGE_LENGTH &&
offset + size > MLXSW_SP_EEPROM_PAGE_LENGTH)
/* Cross pages read, read until offset 256 in low page */
size = MLXSW_SP_EEPROM_PAGE_LENGTH - offset;
i2c_addr = MLXSW_SP_I2C_ADDR_LOW;
if (offset >= MLXSW_SP_EEPROM_PAGE_LENGTH) {
i2c_addr = MLXSW_SP_I2C_ADDR_HIGH;
offset -= MLXSW_SP_EEPROM_PAGE_LENGTH;
}
mlxsw_reg_mcia_pack(mcia_pl, mlxsw_sp_port->mapping.module, mlxsw_reg_mcia_pack(mcia_pl, mlxsw_sp_port->mapping.module,
0, 0, offset, size, MLXSW_SP_QSFP_I2C_ADDR); 0, 0, offset, size, i2c_addr);
err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(mcia), mcia_pl); err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(mcia), mcia_pl);
if (err) if (err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment