Skip to content

Commit 813c2dd

Browse files
Ivan Bornyakovdavem330
authored andcommitted
net: sfp: initialize sfp->i2c_block_size at sfp allocation
sfp->i2c_block_size is initialized at SFP module insertion in sfp_sm_mod_probe(). Because of that, if SFP module was never inserted since boot, sfp_read() call will lead to zero-length I2C read attempt, and not all I2C controllers are happy with zero-length reads. One way to issue sfp_read() on empty SFP cage is to execute ethtool -m. If SFP module was never plugged since boot, there will be a zero-length I2C read attempt. # ethtool -m xge0 i2c i2c-3: adapter quirk: no zero length (addr 0x0050, size 0, read) Cannot get Module EEPROM data: Operation not supported If SFP module was plugged then removed at least once, sfp->i2c_block_size will be initialized and ethtool -m will fail with different exit code and without I2C error # ethtool -m xge0 Cannot get Module EEPROM data: Remote I/O error Fix this by initializing sfp->i2_block_size at struct sfp allocation stage so no wild sfp_read() could issue zero-length I2C read. Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru> Fixes: 0d035be ("net: sfp: VSOL V2801F / CarlitoxxPro CPGOS03-0490 v2.0 workaround") Cc: stable@vger.kernel.org Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5cc33f1 commit 813c2dd

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

drivers/net/phy/sfp.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ static const enum gpiod_flags gpio_flags[] = {
210210
#define SFP_PHY_ADDR 22
211211
#define SFP_PHY_ADDR_ROLLBALL 17
212212

213+
/* SFP_EEPROM_BLOCK_SIZE is the size of data chunk to read the EEPROM
214+
* at a time. Some SFP modules and also some Linux I2C drivers do not like
215+
* reads longer than 16 bytes.
216+
*/
217+
#define SFP_EEPROM_BLOCK_SIZE 16
218+
213219
struct sff_data {
214220
unsigned int gpios;
215221
bool (*module_supported)(const struct sfp_eeprom_id *id);
@@ -1929,11 +1935,7 @@ static int sfp_sm_mod_probe(struct sfp *sfp, bool report)
19291935
u8 check;
19301936
int ret;
19311937

1932-
/* Some SFP modules and also some Linux I2C drivers do not like reads
1933-
* longer than 16 bytes, so read the EEPROM in chunks of 16 bytes at
1934-
* a time.
1935-
*/
1936-
sfp->i2c_block_size = 16;
1938+
sfp->i2c_block_size = SFP_EEPROM_BLOCK_SIZE;
19371939

19381940
ret = sfp_read(sfp, false, 0, &id.base, sizeof(id.base));
19391941
if (ret < 0) {
@@ -2621,6 +2623,7 @@ static struct sfp *sfp_alloc(struct device *dev)
26212623
return ERR_PTR(-ENOMEM);
26222624

26232625
sfp->dev = dev;
2626+
sfp->i2c_block_size = SFP_EEPROM_BLOCK_SIZE;
26242627

26252628
mutex_init(&sfp->sm_mutex);
26262629
mutex_init(&sfp->st_mutex);

0 commit comments

Comments
 (0)