Re: [PATCH net-next v3 2/2] net: mdio: mdio-i2c: Add support for single-byte SMBus operations

From: Maxime Chevallier
Date: Fri Mar 21 2025 - 14:04:04 EST


On Fri, 21 Mar 2025 18:53:51 +0100
Paolo Abeni <pabeni@xxxxxxxxxx> wrote:

> On 3/14/25 5:23 PM, Maxime Chevallier wrote:
> > diff --git a/drivers/net/mdio/mdio-i2c.c b/drivers/net/mdio/mdio-i2c.c
> > index da2001ea1f99..202f486e71f1 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);
>
> External brackets not needed.
>
> > +
> > + 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);
>
> same here.
>
> > +
> > + 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);
>
> and here.
>
> > +
> > + 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;
>
> I would not have noted the above if even this one carried additional
> brackets...

:( You're correct, sorry not to have spotted that before... I'll fix
this for v4.

Maxime