* [PATCH] net: sfp: read eeprom in maximum 16 byte increments
@ 2019-06-02 14:13 Russell King
2019-06-03 19:52 ` Andrew Lunn
2019-06-03 22:17 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Russell King @ 2019-06-02 14:13 UTC (permalink / raw)
To: David S. Miller; +Cc: Andrew Lunn, Florian Fainelli, Heiner Kallweit, netdev
Some SFP modules do not like reads longer than 16 bytes, so read the
EEPROM in chunks of 16 bytes at a time. This behaviour is not specified
in the SFP MSAs, which specifies:
"The serial interface uses the 2-wire serial CMOS E2PROM protocol
defined for the ATMEL AT24C01A/02/04 family of components."
and
"As long as the SFP+ receives an acknowledge, it shall serially clock
out sequential data words. The sequence is terminated when the host
responds with a NACK and a STOP instead of an acknowledge."
We must avoid breaking a read across a 16-bit quantity in the diagnostic
page, thankfully all 16-bit quantities in that page are naturally
aligned.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
drivers/net/phy/sfp.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index d4635c2178d1..71812be0ac64 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -281,6 +281,7 @@ static int sfp_i2c_read(struct sfp *sfp, bool a2, u8 dev_addr, void *buf,
{
struct i2c_msg msgs[2];
u8 bus_addr = a2 ? 0x51 : 0x50;
+ size_t this_len;
int ret;
msgs[0].addr = bus_addr;
@@ -292,11 +293,26 @@ static int sfp_i2c_read(struct sfp *sfp, bool a2, u8 dev_addr, void *buf,
msgs[1].len = len;
msgs[1].buf = buf;
- ret = i2c_transfer(sfp->i2c, msgs, ARRAY_SIZE(msgs));
- if (ret < 0)
- return ret;
+ while (len) {
+ this_len = len;
+ if (this_len > 16)
+ this_len = 16;
- return ret == ARRAY_SIZE(msgs) ? len : 0;
+ msgs[1].len = this_len;
+
+ ret = i2c_transfer(sfp->i2c, msgs, ARRAY_SIZE(msgs));
+ if (ret < 0)
+ return ret;
+
+ if (ret != ARRAY_SIZE(msgs))
+ break;
+
+ msgs[1].buf += this_len;
+ dev_addr += this_len;
+ len -= this_len;
+ }
+
+ return msgs[1].buf - (u8 *)buf;
}
static int sfp_i2c_write(struct sfp *sfp, bool a2, u8 dev_addr, void *buf,
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: sfp: read eeprom in maximum 16 byte increments
2019-06-02 14:13 [PATCH] net: sfp: read eeprom in maximum 16 byte increments Russell King
@ 2019-06-03 19:52 ` Andrew Lunn
2019-06-03 22:17 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2019-06-03 19:52 UTC (permalink / raw)
To: Russell King; +Cc: David S. Miller, Florian Fainelli, Heiner Kallweit, netdev
On Sun, Jun 02, 2019 at 03:13:00PM +0100, Russell King wrote:
> Some SFP modules do not like reads longer than 16 bytes, so read the
> EEPROM in chunks of 16 bytes at a time. This behaviour is not specified
> in the SFP MSAs, which specifies:
>
> "The serial interface uses the 2-wire serial CMOS E2PROM protocol
> defined for the ATMEL AT24C01A/02/04 family of components."
>
> and
>
> "As long as the SFP+ receives an acknowledge, it shall serially clock
> out sequential data words. The sequence is terminated when the host
> responds with a NACK and a STOP instead of an acknowledge."
>
> We must avoid breaking a read across a 16-bit quantity in the diagnostic
> page, thankfully all 16-bit quantities in that page are naturally
> aligned.
>
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: sfp: read eeprom in maximum 16 byte increments
2019-06-02 14:13 [PATCH] net: sfp: read eeprom in maximum 16 byte increments Russell King
2019-06-03 19:52 ` Andrew Lunn
@ 2019-06-03 22:17 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-06-03 22:17 UTC (permalink / raw)
To: rmk+kernel; +Cc: andrew, f.fainelli, hkallweit1, netdev
From: Russell King <rmk+kernel@armlinux.org.uk>
Date: Sun, 02 Jun 2019 15:13:00 +0100
> Some SFP modules do not like reads longer than 16 bytes, so read the
> EEPROM in chunks of 16 bytes at a time. This behaviour is not specified
> in the SFP MSAs, which specifies:
>
> "The serial interface uses the 2-wire serial CMOS E2PROM protocol
> defined for the ATMEL AT24C01A/02/04 family of components."
>
> and
>
> "As long as the SFP+ receives an acknowledge, it shall serially clock
> out sequential data words. The sequence is terminated when the host
> responds with a NACK and a STOP instead of an acknowledge."
>
> We must avoid breaking a read across a 16-bit quantity in the diagnostic
> page, thankfully all 16-bit quantities in that page are naturally
> aligned.
>
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Applied and queued up for -stable.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-06-03 22:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-02 14:13 [PATCH] net: sfp: read eeprom in maximum 16 byte increments Russell King
2019-06-03 19:52 ` Andrew Lunn
2019-06-03 22:17 ` 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).