netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René van Dorst" <opensource@vdorst.com>
To: Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org
Cc: "René van Dorst" <opensource@vdorst.com>
Subject: [PATCH] sfp: sfp_read: split-up request when hw rx buffer is too small.
Date: Wed, 23 Jan 2019 22:20:46 +0100	[thread overview]
Message-ID: <20190123212046.13020-1-opensource@vdorst.com> (raw)

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


             reply	other threads:[~2019-01-23 21:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-23 21:20 René van Dorst [this message]
2019-01-23 21:32 ` [PATCH] sfp: sfp_read: split-up request when hw rx buffer is too small 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190123212046.13020-1-opensource@vdorst.com \
    --to=opensource@vdorst.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).