netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch net] mlxsw: spectrum: Fix EEPROM access in case of SFP/SFP+
@ 2017-09-11  7:42 Jiri Pirko
  2017-09-11 13:58 ` Andrew Lunn
  2017-09-11 17:41 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Jiri Pirko @ 2017-09-11  7:42 UTC (permalink / raw)
  To: netdev; +Cc: davem, arkadis, idosch, flokli, mlxsw

From: Arkadi Sharshevsky <arkadis@mellanox.com>

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: 2ea109039cd3 ("mlxsw: spectrum: Add support for access cable info via ethtool")
Reported-by: Florian Klink <flokli@flokli.de>
Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
Dave, could you please queue this up to STABLE as well? Thanks!
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index ed7cd6c..e080459 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -2545,7 +2545,9 @@ static int mlxsw_sp_flash_device(struct net_device *dev,
 	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,
 					u16 offset, u16 size, void *data,
@@ -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;
 	char eeprom_tmp[MLXSW_SP_REG_MCIA_EEPROM_SIZE];
 	char mcia_pl[MLXSW_REG_MCIA_LEN];
+	u16 i2c_addr;
 	int status;
 	int err;
 
 	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,
-			    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);
 	if (err)
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [patch net] mlxsw: spectrum: Fix EEPROM access in case of SFP/SFP+
  2017-09-11  7:42 [patch net] mlxsw: spectrum: Fix EEPROM access in case of SFP/SFP+ Jiri Pirko
@ 2017-09-11 13:58 ` Andrew Lunn
  2017-09-11 17:27   ` Jiri Pirko
  2017-09-11 17:41 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2017-09-11 13:58 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: netdev, davem, arkadis, idosch, flokli, mlxsw

On Mon, Sep 11, 2017 at 09:42:26AM +0200, Jiri Pirko wrote:
> From: Arkadi Sharshevsky <arkadis@mellanox.com>
> 
> 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.

Shame you cannot/didn't expose the i2c bus as a linux i2c bus. The AT24 code
does not have this bug!

     Andrew

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch net] mlxsw: spectrum: Fix EEPROM access in case of SFP/SFP+
  2017-09-11 13:58 ` Andrew Lunn
@ 2017-09-11 17:27   ` Jiri Pirko
  0 siblings, 0 replies; 4+ messages in thread
From: Jiri Pirko @ 2017-09-11 17:27 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: netdev, davem, arkadis, idosch, flokli, mlxsw

Mon, Sep 11, 2017 at 03:58:26PM CEST, andrew@lunn.ch wrote:
>On Mon, Sep 11, 2017 at 09:42:26AM +0200, Jiri Pirko wrote:
>> From: Arkadi Sharshevsky <arkadis@mellanox.com>
>> 
>> 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.
>
>Shame you cannot/didn't expose the i2c bus as a linux i2c bus. The AT24 code

We cannot.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch net] mlxsw: spectrum: Fix EEPROM access in case of SFP/SFP+
  2017-09-11  7:42 [patch net] mlxsw: spectrum: Fix EEPROM access in case of SFP/SFP+ Jiri Pirko
  2017-09-11 13:58 ` Andrew Lunn
@ 2017-09-11 17:41 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2017-09-11 17:41 UTC (permalink / raw)
  To: jiri; +Cc: netdev, arkadis, idosch, flokli, mlxsw

From: Jiri Pirko <jiri@resnulli.us>
Date: Mon, 11 Sep 2017 09:42:26 +0200

> From: Arkadi Sharshevsky <arkadis@mellanox.com>
> 
> 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: 2ea109039cd3 ("mlxsw: spectrum: Add support for access cable info via ethtool")
> Reported-by: Florian Klink <flokli@flokli.de>
> Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
> Reviewed-by: Ido Schimmel <idosch@mellanox.com>
> Signed-off-by: Jiri Pirko <jiri@mellanox.com>

Applied and queued up for -stable, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-09-11 17:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-11  7:42 [patch net] mlxsw: spectrum: Fix EEPROM access in case of SFP/SFP+ Jiri Pirko
2017-09-11 13:58 ` Andrew Lunn
2017-09-11 17:27   ` Jiri Pirko
2017-09-11 17:41 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).