* [PATCH net-next v4 0/2] net: phy: sfp: Add single-byte SMBus SFP access
@ 2025-03-22 7:57 Maxime Chevallier
2025-03-22 7:57 ` [PATCH net-next v4 1/2] net: phy: sfp: Add support for SMBus module access Maxime Chevallier
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Maxime Chevallier @ 2025-03-22 7:57 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet, Paolo Abeni,
Russell King, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, thomas.petazzoni,
Florian Fainelli, Köry Maincent, Simon Horman,
Romain Gantois, Antoine Tenart, Marek Behún, Sean Anderson,
Bjørn Mork
Hello everyone,
This is V4 for the single-byte SMBus support for SFP cages as well as
embedded PHYs accessed over mdio-i2c.
V4: Cosmetic cleanups reported by Paolo :
- xmas tree in patch 1
- Extra parenthesis in patch 2
V3:
- Rework patch 1 to use i2c_max_block_size
V2:
- Disabled hwmon and add a big warning when in single-byte mode
V3 : https://lore.kernel.org/netdev/20250314162319.516163-1-maxime.chevallier@bootlin.com/
V2 : https://lore.kernel.org/netdev/20250225112043.419189-1-maxime.chevallier@bootlin.com/
V1 : https://lore.kernel.org/netdev/20250223172848.1098621-1-maxime.chevallier@bootlin.com/#t
Maxime
Maxime Chevallier (2):
net: phy: sfp: Add support for SMBus module access
net: mdio: mdio-i2c: Add support for single-byte SMBus operations
drivers/net/mdio/mdio-i2c.c | 79 ++++++++++++++++++++++++++++++++++-
drivers/net/phy/sfp.c | 82 +++++++++++++++++++++++++++++++++----
2 files changed, 152 insertions(+), 9 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next v4 1/2] net: phy: sfp: Add support for SMBus module access
2025-03-22 7:57 [PATCH net-next v4 0/2] net: phy: sfp: Add single-byte SMBus SFP access Maxime Chevallier
@ 2025-03-22 7:57 ` Maxime Chevallier
2025-03-22 15:28 ` Andrew Lunn
2025-03-22 7:57 ` [PATCH net-next v4 2/2] net: mdio: mdio-i2c: Add support for single-byte SMBus operations Maxime Chevallier
2025-03-25 16:20 ` [PATCH net-next v4 0/2] net: phy: sfp: Add single-byte SMBus SFP access patchwork-bot+netdevbpf
2 siblings, 1 reply; 6+ messages in thread
From: Maxime Chevallier @ 2025-03-22 7:57 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet, Paolo Abeni,
Russell King, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, thomas.petazzoni,
Florian Fainelli, Köry Maincent, Simon Horman,
Romain Gantois, Antoine Tenart, Marek Behún, Sean Anderson,
Bjørn Mork
The SFP module's eeprom and internals are accessible through an i2c bus.
It is possible that the SFP might be connected to an SMBus-only
controller, such as the one found in some PHY devices in the VSC85xx
family.
Introduce a set of sfp read/write ops that are going to be used if the
i2c bus is only capable of doing smbus byte accesses.
As Single-byte SMBus transaction go against SFF-8472 and breaks the
atomicity for diagnostics data access, hwmon is disabled in the case
of SMBus access.
Moreover, as this may cause other instabilities, print a warning at
probe time to indicate that the setup may be unreliable because of the
hardware design.
As hwmon may be disabled for both broken EEPROM and smbus, the warnings
are udpated accordingly.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
V4: Fixed xmas tree in read/write functions
drivers/net/phy/sfp.c | 82 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 74 insertions(+), 8 deletions(-)
diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index c88217af44a1..347c1e0e94d9 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -234,6 +234,7 @@ struct sfp {
enum mdio_i2c_proto mdio_protocol;
struct phy_device *mod_phy;
const struct sff_data *type;
+ size_t i2c_max_block_size;
size_t i2c_block_size;
u32 max_power_mW;
@@ -691,14 +692,71 @@ static int sfp_i2c_write(struct sfp *sfp, bool a2, u8 dev_addr, void *buf,
return ret == ARRAY_SIZE(msgs) ? len : 0;
}
-static int sfp_i2c_configure(struct sfp *sfp, struct i2c_adapter *i2c)
+static int sfp_smbus_byte_read(struct sfp *sfp, bool a2, u8 dev_addr,
+ void *buf, size_t len)
{
- if (!i2c_check_functionality(i2c, I2C_FUNC_I2C))
- return -EINVAL;
+ union i2c_smbus_data smbus_data;
+ u8 bus_addr = a2 ? 0x51 : 0x50;
+ u8 *data = buf;
+ int ret;
+
+ while (len) {
+ ret = i2c_smbus_xfer(sfp->i2c, bus_addr, 0,
+ I2C_SMBUS_READ, dev_addr,
+ I2C_SMBUS_BYTE_DATA, &smbus_data);
+ if (ret < 0)
+ return ret;
+
+ *data = smbus_data.byte;
+
+ len--;
+ data++;
+ dev_addr++;
+ }
+
+ return data - (u8 *)buf;
+}
+
+static int sfp_smbus_byte_write(struct sfp *sfp, bool a2, u8 dev_addr,
+ void *buf, size_t len)
+{
+ union i2c_smbus_data smbus_data;
+ u8 bus_addr = a2 ? 0x51 : 0x50;
+ u8 *data = buf;
+ int ret;
+ while (len) {
+ smbus_data.byte = *data;
+ ret = i2c_smbus_xfer(sfp->i2c, bus_addr, 0,
+ I2C_SMBUS_WRITE, dev_addr,
+ I2C_SMBUS_BYTE_DATA, &smbus_data);
+ if (ret)
+ return ret;
+
+ len--;
+ data++;
+ dev_addr++;
+ }
+
+ return 0;
+}
+
+static int sfp_i2c_configure(struct sfp *sfp, struct i2c_adapter *i2c)
+{
sfp->i2c = i2c;
- sfp->read = sfp_i2c_read;
- sfp->write = sfp_i2c_write;
+
+ if (i2c_check_functionality(i2c, I2C_FUNC_I2C)) {
+ sfp->read = sfp_i2c_read;
+ sfp->write = sfp_i2c_write;
+ sfp->i2c_max_block_size = SFP_EEPROM_BLOCK_SIZE;
+ } else if (i2c_check_functionality(i2c, I2C_FUNC_SMBUS_BYTE_DATA)) {
+ sfp->read = sfp_smbus_byte_read;
+ sfp->write = sfp_smbus_byte_write;
+ sfp->i2c_max_block_size = 1;
+ } else {
+ sfp->i2c = NULL;
+ return -EINVAL;
+ }
return 0;
}
@@ -1594,7 +1652,7 @@ static void sfp_hwmon_probe(struct work_struct *work)
*/
if (sfp->i2c_block_size < 2) {
dev_info(sfp->dev,
- "skipping hwmon device registration due to broken EEPROM\n");
+ "skipping hwmon device registration\n");
dev_info(sfp->dev,
"diagnostic EEPROM area cannot be read atomically to guarantee data coherency\n");
return;
@@ -2201,7 +2259,7 @@ static int sfp_sm_mod_probe(struct sfp *sfp, bool report)
u8 check;
int ret;
- sfp->i2c_block_size = SFP_EEPROM_BLOCK_SIZE;
+ sfp->i2c_block_size = sfp->i2c_max_block_size;
ret = sfp_read(sfp, false, 0, &id.base, sizeof(id.base));
if (ret < 0) {
@@ -2941,7 +2999,6 @@ static struct sfp *sfp_alloc(struct device *dev)
return ERR_PTR(-ENOMEM);
sfp->dev = dev;
- sfp->i2c_block_size = SFP_EEPROM_BLOCK_SIZE;
mutex_init(&sfp->sm_mutex);
mutex_init(&sfp->st_mutex);
@@ -3115,6 +3172,15 @@ static int sfp_probe(struct platform_device *pdev)
if (!sfp->sfp_bus)
return -ENOMEM;
+ if (sfp->i2c_max_block_size < 2)
+ dev_warn(sfp->dev,
+ "Please note:\n"
+ "This SFP cage is accessed via an SMBus only capable of single byte\n"
+ "transactions. Some features are disabled, other may be unreliable or\n"
+ "sporadically fail. Use with caution. There is nothing that the kernel\n"
+ "or community can do to fix it, the kernel will try best efforts. Please\n"
+ "verify any problems on hardware that supports multi-byte I2C transactions.\n");
+
sfp_debugfs_init(sfp);
return 0;
--
2.48.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next v4 2/2] net: mdio: mdio-i2c: Add support for single-byte SMBus operations
2025-03-22 7:57 [PATCH net-next v4 0/2] net: phy: sfp: Add single-byte SMBus SFP access Maxime Chevallier
2025-03-22 7:57 ` [PATCH net-next v4 1/2] net: phy: sfp: Add support for SMBus module access Maxime Chevallier
@ 2025-03-22 7:57 ` Maxime Chevallier
2025-03-22 15:43 ` Andrew Lunn
2025-03-25 16:20 ` [PATCH net-next v4 0/2] net: phy: sfp: Add single-byte SMBus SFP access patchwork-bot+netdevbpf
2 siblings, 1 reply; 6+ messages in thread
From: Maxime Chevallier @ 2025-03-22 7:57 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet, Paolo Abeni,
Russell King, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, thomas.petazzoni,
Florian Fainelli, Köry Maincent, Simon Horman,
Romain Gantois, Antoine Tenart, Marek Behún, Sean Anderson,
Bjørn Mork
PHYs that are within copper SFP modules have their MDIO bus accessible
through address 0x56 (usually) on the i2c bus. The MDIO-I2C bridge is
desgned for 16 bits accesses, but we can also perform 8bits accesses by
reading/writing the high and low bytes sequentially.
This commit adds support for this type of accesses, thus supporting
smbus controllers such as the one in the VSC8552.
This was only tested on Copper SFP modules that embed a Marvell 88e1111
PHY.
Tested-by: Sean Anderson <sean.anderson@linux.dev>
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
V4: Removed extra parenthesis
drivers/net/mdio/mdio-i2c.c | 79 ++++++++++++++++++++++++++++++++++++-
1 file changed, 78 insertions(+), 1 deletion(-)
diff --git a/drivers/net/mdio/mdio-i2c.c b/drivers/net/mdio/mdio-i2c.c
index da2001ea1f99..53e96bfab542 100644
--- a/drivers/net/mdio/mdio-i2c.c
+++ b/drivers/net/mdio/mdio-i2c.c
@@ -106,6 +106,62 @@ static int i2c_mii_write_default_c22(struct mii_bus *bus, int phy_id, int reg,
return i2c_mii_write_default_c45(bus, phy_id, -1, reg, val);
}
+static int smbus_byte_mii_read_default_c22(struct mii_bus *bus, int phy_id,
+ int reg)
+{
+ struct i2c_adapter *i2c = bus->priv;
+ union i2c_smbus_data smbus_data;
+ int val = 0, ret;
+
+ if (!i2c_mii_valid_phy_id(phy_id))
+ return 0;
+
+ ret = i2c_smbus_xfer(i2c, i2c_mii_phy_addr(phy_id), 0,
+ I2C_SMBUS_READ, reg,
+ I2C_SMBUS_BYTE_DATA, &smbus_data);
+ if (ret < 0)
+ return ret;
+
+ val = (smbus_data.byte & 0xff) << 8;
+
+ ret = i2c_smbus_xfer(i2c, i2c_mii_phy_addr(phy_id), 0,
+ I2C_SMBUS_READ, reg,
+ I2C_SMBUS_BYTE_DATA, &smbus_data);
+ if (ret < 0)
+ return ret;
+
+ val |= smbus_data.byte & 0xff;
+
+ return val;
+}
+
+static int smbus_byte_mii_write_default_c22(struct mii_bus *bus, int phy_id,
+ int reg, u16 val)
+{
+ struct i2c_adapter *i2c = bus->priv;
+ union i2c_smbus_data smbus_data;
+ int ret;
+
+ if (!i2c_mii_valid_phy_id(phy_id))
+ return 0;
+
+ smbus_data.byte = (val & 0xff00) >> 8;
+
+ ret = i2c_smbus_xfer(i2c, i2c_mii_phy_addr(phy_id), 0,
+ I2C_SMBUS_WRITE, reg,
+ I2C_SMBUS_BYTE_DATA, &smbus_data);
+ if (ret < 0)
+ return ret;
+
+ smbus_data.byte = val & 0xff;
+
+ ret = i2c_smbus_xfer(i2c, i2c_mii_phy_addr(phy_id), 0,
+ I2C_SMBUS_WRITE, reg,
+ I2C_SMBUS_BYTE_DATA, &smbus_data);
+
+ return ret < 0 ? ret : 0;
+}
+
/* RollBall SFPs do not access internal PHY via I2C address 0x56, but
* instead via address 0x51, when SFP page is set to 0x03 and password to
* 0xffffffff.
@@ -378,13 +434,26 @@ static int i2c_mii_init_rollball(struct i2c_adapter *i2c)
return 0;
}
+static bool mdio_i2c_check_functionality(struct i2c_adapter *i2c,
+ enum mdio_i2c_proto protocol)
+{
+ if (i2c_check_functionality(i2c, I2C_FUNC_I2C))
+ return true;
+
+ if (i2c_check_functionality(i2c, I2C_FUNC_SMBUS_BYTE_DATA) &&
+ protocol == MDIO_I2C_MARVELL_C22)
+ return true;
+
+ return false;
+}
+
struct mii_bus *mdio_i2c_alloc(struct device *parent, struct i2c_adapter *i2c,
enum mdio_i2c_proto protocol)
{
struct mii_bus *mii;
int ret;
- if (!i2c_check_functionality(i2c, I2C_FUNC_I2C))
+ if (!mdio_i2c_check_functionality(i2c, protocol))
return ERR_PTR(-EINVAL);
mii = mdiobus_alloc();
@@ -395,6 +464,14 @@ 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)) {
+ mii->read = smbus_byte_mii_read_default_c22;
+ mii->write = smbus_byte_mii_write_default_c22;
+ return mii;
+ }
+
switch (protocol) {
case MDIO_I2C_ROLLBALL:
ret = i2c_mii_init_rollball(i2c);
--
2.48.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v4 1/2] net: phy: sfp: Add support for SMBus module access
2025-03-22 7:57 ` [PATCH net-next v4 1/2] net: phy: sfp: Add support for SMBus module access Maxime Chevallier
@ 2025-03-22 15:28 ` Andrew Lunn
0 siblings, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2025-03-22 15:28 UTC (permalink / raw)
To: Maxime Chevallier
Cc: davem, Jakub Kicinski, Eric Dumazet, Paolo Abeni, Russell King,
Heiner Kallweit, netdev, linux-kernel, thomas.petazzoni,
Florian Fainelli, Köry Maincent, Simon Horman,
Romain Gantois, Antoine Tenart, Marek Behún, Sean Anderson,
Bjørn Mork
On Sat, Mar 22, 2025 at 08:57:44AM +0100, Maxime Chevallier wrote:
> The SFP module's eeprom and internals are accessible through an i2c bus.
>
> It is possible that the SFP might be connected to an SMBus-only
> controller, such as the one found in some PHY devices in the VSC85xx
> family.
>
> Introduce a set of sfp read/write ops that are going to be used if the
> i2c bus is only capable of doing smbus byte accesses.
>
> As Single-byte SMBus transaction go against SFF-8472 and breaks the
> atomicity for diagnostics data access, hwmon is disabled in the case
> of SMBus access.
>
> Moreover, as this may cause other instabilities, print a warning at
> probe time to indicate that the setup may be unreliable because of the
> hardware design.
>
> As hwmon may be disabled for both broken EEPROM and smbus, the warnings
> are udpated accordingly.
>
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v4 2/2] net: mdio: mdio-i2c: Add support for single-byte SMBus operations
2025-03-22 7:57 ` [PATCH net-next v4 2/2] net: mdio: mdio-i2c: Add support for single-byte SMBus operations Maxime Chevallier
@ 2025-03-22 15:43 ` Andrew Lunn
0 siblings, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2025-03-22 15:43 UTC (permalink / raw)
To: Maxime Chevallier
Cc: davem, Jakub Kicinski, Eric Dumazet, Paolo Abeni, Russell King,
Heiner Kallweit, netdev, linux-kernel, thomas.petazzoni,
Florian Fainelli, Köry Maincent, Simon Horman,
Romain Gantois, Antoine Tenart, Marek Behún, Sean Anderson,
Bjørn Mork
On Sat, Mar 22, 2025 at 08:57:45AM +0100, Maxime Chevallier wrote:
> PHYs that are within copper SFP modules have their MDIO bus accessible
> through address 0x56 (usually) on the i2c bus. The MDIO-I2C bridge is
> desgned for 16 bits accesses, but we can also perform 8bits accesses by
> reading/writing the high and low bytes sequentially.
>
> This commit adds support for this type of accesses, thus supporting
> smbus controllers such as the one in the VSC8552.
>
> This was only tested on Copper SFP modules that embed a Marvell 88e1111
> PHY.
>
> Tested-by: Sean Anderson <sean.anderson@linux.dev>
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v4 0/2] net: phy: sfp: Add single-byte SMBus SFP access
2025-03-22 7:57 [PATCH net-next v4 0/2] net: phy: sfp: Add single-byte SMBus SFP access Maxime Chevallier
2025-03-22 7:57 ` [PATCH net-next v4 1/2] net: phy: sfp: Add support for SMBus module access Maxime Chevallier
2025-03-22 7:57 ` [PATCH net-next v4 2/2] net: mdio: mdio-i2c: Add support for single-byte SMBus operations Maxime Chevallier
@ 2025-03-25 16:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-03-25 16:20 UTC (permalink / raw)
To: Maxime Chevallier
Cc: davem, andrew, kuba, edumazet, pabeni, linux, hkallweit1, netdev,
linux-kernel, thomas.petazzoni, f.fainelli, kory.maincent, horms,
romain.gantois, atenart, kabel, sean.anderson, bjorn
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sat, 22 Mar 2025 08:57:43 +0100 you wrote:
> Hello everyone,
>
> This is V4 for the single-byte SMBus support for SFP cages as well as
> embedded PHYs accessed over mdio-i2c.
>
> V4: Cosmetic cleanups reported by Paolo :
> - xmas tree in patch 1
> - Extra parenthesis in patch 2
>
> [...]
Here is the summary with links:
- [net-next,v4,1/2] net: phy: sfp: Add support for SMBus module access
https://git.kernel.org/netdev/net-next/c/7662abf4db94
- [net-next,v4,2/2] net: mdio: mdio-i2c: Add support for single-byte SMBus operations
https://git.kernel.org/netdev/net-next/c/d4bd3aca33c2
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-03-25 16:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-22 7:57 [PATCH net-next v4 0/2] net: phy: sfp: Add single-byte SMBus SFP access Maxime Chevallier
2025-03-22 7:57 ` [PATCH net-next v4 1/2] net: phy: sfp: Add support for SMBus module access Maxime Chevallier
2025-03-22 15:28 ` Andrew Lunn
2025-03-22 7:57 ` [PATCH net-next v4 2/2] net: mdio: mdio-i2c: Add support for single-byte SMBus operations Maxime Chevallier
2025-03-22 15:43 ` Andrew Lunn
2025-03-25 16:20 ` [PATCH net-next v4 0/2] net: phy: sfp: Add single-byte SMBus SFP access patchwork-bot+netdevbpf
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).