[PATCH net-next 5/6] net: mdio: mdio-i2c: Add single-byte C22 MDIO protocol

Maxime Chevallier posted 6 patches 3 weeks, 4 days ago
[PATCH net-next 5/6] net: mdio: mdio-i2c: Add single-byte C22 MDIO protocol
Posted by Maxime Chevallier 3 weeks, 4 days ago
In commit d4bd3aca33c2 ("net: mdio: mdio-i2c: Add support for single-byte
SMBus operations"), we introduced single-byte SMBus support for the
mdio-i2c. This was intended to deal with the case where the I2C adapter
that accesses the SFP module is limited to single-byte smbus accesses.
We find this type of adapters in some PHY devices such as the VSC8552.

It was discovered that some SFP modules have a built-in PHY that only
reply to single-byte smbus accesses. This is the case for the Prolabs
GLC-GE-100FX-C SGMII to 100FX module, which contains a Broadcom BCM5461
PHY.

In that case, trying to access the PHY with regular 16-bit transactions
with the mdio-i2c driver causes the PHY to stall the i2c bus completely,
without any way to recover. Accessing it in single-byte mode however,
works fine.

Add a dedicated MDIO_I2C_SINGLE_BYTE_C22 protocol type, so that we can
setup the mdio-i2c driver accordingly. The good news here is that this
should work on pretty much every setup, as a true I2C adapter is also
capable of single-byte accesses thanks to the i2c smbus emulation layer.

Some care will need to be taken should we add support for word-only
smbus adapters.

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 drivers/net/mdio/mdio-i2c.c   | 12 ++++++++----
 drivers/net/phy/sfp.c         |  1 +
 include/linux/mdio/mdio-i2c.h |  1 +
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/net/mdio/mdio-i2c.c b/drivers/net/mdio/mdio-i2c.c
index ed20352a589a..86ae8a5c0ebd 100644
--- a/drivers/net/mdio/mdio-i2c.c
+++ b/drivers/net/mdio/mdio-i2c.c
@@ -452,7 +452,8 @@ static bool mdio_i2c_check_functionality(struct i2c_adapter *i2c,
 		return true;
 
 	if (i2c_check_functionality(i2c, I2C_FUNC_SMBUS_BYTE_DATA) &&
-	    protocol == MDIO_I2C_MARVELL_C22)
+	    (protocol == MDIO_I2C_MARVELL_C22 ||
+	     protocol == MDIO_I2C_SINGLE_BYTE_C22))
 		return true;
 
 	return false;
@@ -475,9 +476,12 @@ struct mii_bus *mdio_i2c_alloc(struct device *parent, struct i2c_adapter *i2c,
 	mii->parent = parent;
 	mii->priv = i2c;
 
-	/* Only use SMBus if we have no other choice */
-	if (i2c_check_functionality(i2c, I2C_FUNC_SMBUS_BYTE_DATA) &&
-	    !i2c_check_functionality(i2c, I2C_FUNC_I2C)) {
+	/* Only use single-byte SMBus if explicitly asked, or if we have no
+	 * other choice.
+	 */
+	if (protocol == MDIO_I2C_SINGLE_BYTE_C22 ||
+	    (i2c_check_functionality(i2c, I2C_FUNC_SMBUS_BYTE_DATA) &&
+	    !i2c_check_functionality(i2c, I2C_FUNC_I2C))) {
 		mii->read = smbus_byte_mii_read_default_c22;
 		mii->write = smbus_byte_mii_write_default_c22;
 		return mii;
diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 1f9112efef62..bff91735f681 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -2016,6 +2016,7 @@ static int sfp_sm_probe_for_phy(struct sfp *sfp)
 		break;
 
 	case MDIO_I2C_MARVELL_C22:
+	case MDIO_I2C_SINGLE_BYTE_C22:
 		err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR, false);
 		break;
 
diff --git a/include/linux/mdio/mdio-i2c.h b/include/linux/mdio/mdio-i2c.h
index 65b550a6fc32..f51c474da5b1 100644
--- a/include/linux/mdio/mdio-i2c.h
+++ b/include/linux/mdio/mdio-i2c.h
@@ -16,6 +16,7 @@ enum mdio_i2c_proto {
 	MDIO_I2C_MARVELL_C22,
 	MDIO_I2C_C45,
 	MDIO_I2C_ROLLBALL,
+	MDIO_I2C_SINGLE_BYTE_C22,
 };
 
 struct mii_bus *mdio_i2c_alloc(struct device *parent, struct i2c_adapter *i2c,
-- 
2.49.0