> +static int mdiobus_probe_mmd_read(struct mii_bus *bus, int prtad, int devad,
> + u16 regnum)
> +{
> + int ret;
> +
> + /* For backwards compatibility, treat MDIOBUS_NO_CAP as c45 capable */
> + if (bus->probe_capabilities == MDIOBUS_NO_CAP ||
> + bus->probe_capabilities >= MDIOBUS_C45)
Maybe we should do the work and mark up those that are C45 capable. At
a quick count, see 16 of them.
> + return mdiobus_c45_read(bus, prtad, devad, regnum);
> +
> + mutex_lock(&bus->mdio_lock);
> +
> + /* Write the desired MMD Devad */
> + ret = __mdiobus_write(bus, prtad, MII_MMD_CTRL, devad);
> + if (ret)
> + goto out;
> +
> + /* Write the desired MMD register address */
> + ret = __mdiobus_write(bus, prtad, MII_MMD_DATA, regnum);
> + if (ret)
> + goto out;
> +
> + /* Select the Function : DATA with no post increment */
> + ret = __mdiobus_write(bus, prtad, MII_MMD_CTRL,
> + devad | MII_MMD_CTRL_NOINCR);
> + if (ret)
> + goto out;
Make mmd_phy_indirect() usable, rather then repeat it.
Andrew
Am 2022-03-23 20:39, schrieb Andrew Lunn:
>> +static int mdiobus_probe_mmd_read(struct mii_bus *bus, int prtad, int
>> devad,
>> + u16 regnum)
>> +{
>> + int ret;
>> +
>> + /* For backwards compatibility, treat MDIOBUS_NO_CAP as c45 capable
>> */
>> + if (bus->probe_capabilities == MDIOBUS_NO_CAP ||
>> + bus->probe_capabilities >= MDIOBUS_C45)
>
> Maybe we should do the work and mark up those that are C45 capable. At
> a quick count, see 16 of them.
You mean look at they are MDIOBUS_C45, MDIOBUS_C22_C45 or MDIOBUS_C22
and drop MDIOBUS_NO_CAP?
>
>> + return mdiobus_c45_read(bus, prtad, devad, regnum);
>> +
>> + mutex_lock(&bus->mdio_lock);
>> +
>> + /* Write the desired MMD Devad */
>> + ret = __mdiobus_write(bus, prtad, MII_MMD_CTRL, devad);
>> + if (ret)
>> + goto out;
>> +
>> + /* Write the desired MMD register address */
>> + ret = __mdiobus_write(bus, prtad, MII_MMD_DATA, regnum);
>> + if (ret)
>> + goto out;
>> +
>> + /* Select the Function : DATA with no post increment */
>> + ret = __mdiobus_write(bus, prtad, MII_MMD_CTRL,
>> + devad | MII_MMD_CTRL_NOINCR);
>> + if (ret)
>> + goto out;
>
> Make mmd_phy_indirect() usable, rather then repeat it.
I actually had that. But mmd_phy_indirect() doesn't check
the return code and neither does the __phy_write_mmd() it
actually deliberatly sets "ret = 0". So I wasn't sure. If you
are fine with a changed code flow in the error case, then sure.
I.e. mmd_phy_indirect() always (try to) do three accesses; with
error checks it might end after the first. If you are fine
with the error checks, should __phy_write_mmd() also check the
last mdiobus_write()?
-michael
Am 2022-03-23 20:39, schrieb Andrew Lunn:
>> +static int mdiobus_probe_mmd_read(struct mii_bus *bus, int prtad, int
>> devad,
>> + u16 regnum)
>> +{
>> + int ret;
>> +
>> + /* For backwards compatibility, treat MDIOBUS_NO_CAP as c45 capable
>> */
>> + if (bus->probe_capabilities == MDIOBUS_NO_CAP ||
>> + bus->probe_capabilities >= MDIOBUS_C45)
>
> Maybe we should do the work and mark up those that are C45 capable. At
> a quick count, see 16 of them.
I guess you grepped for MII_ADDR_C45 and had a look who
actually handled it correctly. Correct?
Let's say we mark these as either MDIOBUS_C45 or MDIOBUS_C45_C22,
can we then drop MDIOBUS_NO_CAP and make MDIOBUS_C22 the default
value (i.e. value 0) or do we have to go through all the mdio drivers
and add bus->probe_capabilities = MDIOBUS_C22 ? Grepping for
{of_,}mdiobus_register lists quite a few of them.
-michael
On Wed, Mar 23, 2022 at 11:14:11PM +0100, Michael Walle wrote:
> I actually had that. But mmd_phy_indirect() doesn't check
> the return code and neither does the __phy_write_mmd() it
> actually deliberatly sets "ret = 0". So I wasn't sure. If you
> are fine with a changed code flow in the error case, then sure.
> I.e. mmd_phy_indirect() always (try to) do three accesses; with
> error checks it might end after the first. If you are fine
> with the error checks, should __phy_write_mmd() also check the
> last mdiobus_write()?
The reason for that goes back to
commit a59a4d1921664da63d801ba477950114c71c88c9
phy: add the EEE support and the way to access to the MMD registers.
and to maintain compatibility with that; if we start checking for
errors now, we might trigger a kernel regression sadly.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Am 2022-03-30 18:18, schrieb Russell King (Oracle):
> On Wed, Mar 23, 2022 at 11:14:11PM +0100, Michael Walle wrote:
>> I actually had that. But mmd_phy_indirect() doesn't check
>> the return code and neither does the __phy_write_mmd() it
>> actually deliberatly sets "ret = 0". So I wasn't sure. If you
>> are fine with a changed code flow in the error case, then sure.
>> I.e. mmd_phy_indirect() always (try to) do three accesses; with
>> error checks it might end after the first. If you are fine
>> with the error checks, should __phy_write_mmd() also check the
>> last mdiobus_write()?
>
> The reason for that goes back to
> commit a59a4d1921664da63d801ba477950114c71c88c9
> phy: add the EEE support and the way to access to the MMD
> registers.
>
> and to maintain compatibility with that; if we start checking for
> errors now, we might trigger a kernel regression sadly.
I see that this is the commit which introduced the mmd_phy_indirect()
function, but I don't see why there is no return code checking.
Unlike now, there is a check for the last read (the one who
reads MII_MMD_DATA). That read which might return garbage if any
write has failed before - or if the bus is completely dead,
return an error. Current code will just return 0.
In any case, I don't have a strong opinion here. I just don't
see how that function could be reused while adding error checks
and without making it ugly, so I've just duplicated it.
Maybe something like this:
static int __phy_mmd_indirect_common(struct mii_bus *bus, int prtad,
int devad, int addr,
bool check_rc)
{
int ret;
/* Write the desired MMD Devad */
ret = __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, devad);
if (check_rc && ret)
return ret;
/* Write the desired MMD register address */
ret = __mdiobus_write(bus, phy_addr, MII_MMD_DATA, regnum);
if (check_rc && ret)
return ret;
/* Select the Function : DATA with no post increment */
ret = __mdiobus_write(bus, phy_addr, MII_MMD_CTRL,
devad | MII_MMD_CTRL_NOINCR);
if (check_rc && ret)
return ret;
return 0;
}
int __phy_mmd_indirect(struct mii_bus *bus, int prtad,
int devad, int addr)
{
return __phy_mmd_indirect_common(bus, prtad, devad,
addr, true);
}
/* some function doc about deliberatly no error checking.. */
void __phy_mmd_indirect_legacy(struct mii_bus *bus, int prtad,
int devad, int addr)
{
__phy_mmd_indirect_common(bus, prtad, devad,
addr, false);
}
should the last two functions be static inline?
-michael