netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sfp: sfp_read: split-up request when hw rx buffer is too small.
@ 2019-01-23 21:20 René van Dorst
  2019-01-23 21:32 ` Andrew Lunn
  2019-01-23 22:43 ` Florian Fainelli
  0 siblings, 2 replies; 10+ messages in thread
From: René van Dorst @ 2019-01-23 21:20 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, Heiner Kallweit, David S. Miller,
	netdev
  Cc: René van Dorst

Without this patch sfp code retries to read the full struct sfp_eeprom_id
id out of the SFP eeprom. Sizeof(id) is 96 bytes.
My i2c hardware, Mediatek mt7621, has a rx buffer of 64 bytes.
So sfp_read gets -NOSUPPORTED back on his turn return -EAGAIN.
Same issue is with the SFP_EXT_STATUS data which is 92 bytes.

By split-up the request in multiple smaller requests with a max size of i2c
max_read_len, we can readout the SFP module successfully.

Tested with MT7621 and two Fiberstore modules SFP-GB-GE-T and SFP-GE-BX.

Signed-off-by: René van Dorst <opensource@vdorst.com>
---
 drivers/net/phy/sfp.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index fd8bb998ae52..1352a19571cd 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -367,7 +367,28 @@ static void sfp_set_state(struct sfp *sfp, unsigned int state)
 
 static int sfp_read(struct sfp *sfp, bool a2, u8 addr, void *buf, size_t len)
 {
-	return sfp->read(sfp, a2, addr, buf, len);
+	const struct i2c_adapter_quirks *q = sfp->i2c->quirks;
+	int ret;
+	size_t rx_bytes = 0;
+
+	/* Many i2c hw have limited rx buffers, split-up request when needed. */
+	while ((q->max_read_len) && (len > q->max_read_len)) {
+		ret = sfp->read(sfp, a2, addr, buf, q->max_read_len);
+		if (ret < 0)
+			return ret;
+		rx_bytes += ret;
+		addr += q->max_read_len;
+		buf += q->max_read_len;
+		len -= q->max_read_len;
+	}
+
+	ret = sfp->read(sfp, a2, addr, buf, len);
+	if (ret < 0)
+		return ret;
+
+	rx_bytes += ret;
+
+	return rx_bytes;
 }
 
 static int sfp_write(struct sfp *sfp, bool a2, u8 addr, void *buf, size_t len)
-- 
2.19.1


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

end of thread, other threads:[~2019-01-25 22:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-23 21:20 [PATCH] sfp: sfp_read: split-up request when hw rx buffer is too small René van Dorst
2019-01-23 21:32 ` Andrew Lunn
2019-01-24 14:03   ` René van Dorst
2019-01-24 14:12     ` Andrew Lunn
2019-01-24 14:46       ` René van Dorst
2019-01-23 22:43 ` Florian Fainelli
2019-01-24 13:15   ` René van Dorst
2019-01-25 21:58     ` René van Dorst
2019-01-25 22:28       ` Florian Fainelli
2019-01-25 22:43         ` Andrew Lunn

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).