Skip to content

Commit 9a06fe0

Browse files
committed
Merge branch 'sfp-eeprom'
Ivan Bornyakov says: ==================== net: fix EEPROM read of absent SFP module The patchset is to improve EEPROM read requests when SFP module is absent. ChangeLog: v1: https://lore.kernel.org/netdev/20230405153900.747-1-i.bornyakov@metrotek.ru/ v2: * reword commit message of "net: sfp: initialize sfp->i2c_block_size at sfp allocation" * add second patch to eliminate excessive I2C transfers in sfp_module_eeprom() and sfp_module_eeprom_by_page() ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 5cc33f1 + bef227c commit 9a06fe0

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

drivers/net/phy/sfp.c

Lines changed: 14 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) {
@@ -2485,6 +2487,9 @@ static int sfp_module_eeprom(struct sfp *sfp, struct ethtool_eeprom *ee,
24852487
unsigned int first, last, len;
24862488
int ret;
24872489

2490+
if (!(sfp->state & SFP_F_PRESENT))
2491+
return -ENODEV;
2492+
24882493
if (ee->len == 0)
24892494
return -EINVAL;
24902495

@@ -2517,6 +2522,9 @@ static int sfp_module_eeprom_by_page(struct sfp *sfp,
25172522
const struct ethtool_module_eeprom *page,
25182523
struct netlink_ext_ack *extack)
25192524
{
2525+
if (!(sfp->state & SFP_F_PRESENT))
2526+
return -ENODEV;
2527+
25202528
if (page->bank) {
25212529
NL_SET_ERR_MSG(extack, "Banks not supported");
25222530
return -EOPNOTSUPP;
@@ -2621,6 +2629,7 @@ static struct sfp *sfp_alloc(struct device *dev)
26212629
return ERR_PTR(-ENOMEM);
26222630

26232631
sfp->dev = dev;
2632+
sfp->i2c_block_size = SFP_EEPROM_BLOCK_SIZE;
26242633

26252634
mutex_init(&sfp->sm_mutex);
26262635
mutex_init(&sfp->st_mutex);

0 commit comments

Comments
 (0)