netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Hancock <hancock@sedsystems.ca>
To: netdev@vger.kernel.org
Cc: linux@armlinux.org.uk, Robert Hancock <hancock@sedsystems.ca>
Subject: [PATCH net-next] net: sfp: Use smaller chunk size when reading I2C data
Date: Fri, 31 May 2019 13:18:03 -0600	[thread overview]
Message-ID: <1559330285-30246-3-git-send-email-hancock@sedsystems.ca> (raw)
In-Reply-To: <1559330285-30246-1-git-send-email-hancock@sedsystems.ca>

The SFP driver was reading up to 256 bytes of I2C data from the SFP
module in a single chunk. However, some I2C controllers do not support
reading that many bytes in a single transaction. Change to use a more
compatible 16-byte chunk size, since this is not performance critical.

Signed-off-by: Robert Hancock <hancock@sedsystems.ca>
---
 drivers/net/phy/sfp.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 6b6c83d..23a40a7 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -1651,7 +1651,7 @@ static int sfp_module_info(struct sfp *sfp, struct ethtool_modinfo *modinfo)
 static int sfp_module_eeprom(struct sfp *sfp, struct ethtool_eeprom *ee,
 			     u8 *data)
 {
-	unsigned int first, last, len;
+	unsigned int first, last;
 	int ret;
 
 	if (ee->len == 0)
@@ -1659,26 +1659,36 @@ static int sfp_module_eeprom(struct sfp *sfp, struct ethtool_eeprom *ee,
 
 	first = ee->offset;
 	last = ee->offset + ee->len;
-	if (first < ETH_MODULE_SFF_8079_LEN) {
-		len = min_t(unsigned int, last, ETH_MODULE_SFF_8079_LEN);
-		len -= first;
 
-		ret = sfp_read(sfp, false, first, data, len);
+	while (first < last) {
+		bool a2;
+		unsigned int this_addr, len;
+
+		if (first < ETH_MODULE_SFF_8079_LEN) {
+			len = min_t(unsigned int, last,
+				    ETH_MODULE_SFF_8079_LEN);
+			len -= first;
+			a2 = false;
+			this_addr = first;
+		} else {
+			len = min_t(unsigned int, last,
+				    ETH_MODULE_SFF_8472_LEN);
+			len -= first;
+			a2 = true;
+			this_addr = first - ETH_MODULE_SFF_8079_LEN;
+		}
+		/* Some I2C adapters cannot read 256 bytes in a single read.
+		 * Use a smaller chunk size to ensure we are within limits.
+		 */
+		len = min_t(unsigned int, len, 16);
+
+		ret = sfp_read(sfp, a2, this_addr, data, len);
 		if (ret < 0)
 			return ret;
 
 		first += len;
 		data += len;
 	}
-	if (first < ETH_MODULE_SFF_8472_LEN && last > ETH_MODULE_SFF_8079_LEN) {
-		len = min_t(unsigned int, last, ETH_MODULE_SFF_8472_LEN);
-		len -= first;
-		first -= ETH_MODULE_SFF_8079_LEN;
-
-		ret = sfp_read(sfp, true, first, data, len);
-		if (ret < 0)
-			return ret;
-	}
 	return 0;
 }
 
-- 
1.8.3.1


  parent reply	other threads:[~2019-05-31 19:18 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-31 19:18 [PATCH net-next] net: sfp: Set 1000BaseX support flag for 1000BaseT modules Robert Hancock
2019-05-31 19:18 ` [PATCH net-next] net: sfp: Stop SFP polling during shutdown Robert Hancock
2019-05-31 20:12   ` Russell King - ARM Linux admin
2019-05-31 22:40     ` Robert Hancock
2019-05-31 19:18 ` Robert Hancock [this message]
2019-05-31 20:13   ` [PATCH net-next] net: sfp: Use smaller chunk size when reading I2C data Russell King - ARM Linux admin
2019-05-31 19:18 ` [PATCH net-next] net: phy: phylink: add fallback from SGMII to 1000BaseX Robert Hancock
2019-05-31 20:18   ` Russell King - ARM Linux admin
2019-06-01  0:17     ` Robert Hancock
2019-06-02 15:15       ` Russell King - ARM Linux admin
2019-06-07 18:10         ` Robert Hancock
2019-06-07 18:34           ` Russell King - ARM Linux admin
2019-06-01  9:46   ` Sergei Shtylyov
2019-05-31 19:18 ` [PATCH net-next] net: phy: phylink: support using device PHY in fixed or 802.3z mode Robert Hancock
2019-05-31 19:29   ` David Miller
2019-05-31 19:41     ` Robert Hancock
2019-05-31 19:42       ` David Miller
2019-05-31 20:31   ` Russell King - ARM Linux admin
2019-06-01  0:33     ` Robert Hancock
2019-06-01 20:10       ` Russell King - ARM Linux admin
2019-06-07 18:15         ` Robert Hancock
2019-05-31 20:11 ` [PATCH net-next] net: sfp: Set 1000BaseX support flag for 1000BaseT modules Russell King - ARM Linux admin

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=1559330285-30246-3-git-send-email-hancock@sedsystems.ca \
    --to=hancock@sedsystems.ca \
    --cc=linux@armlinux.org.uk \
    --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).