Re: [PATCH NET V6 1/2] net: phy: Add phy loopback support in net phy framework
From: Yunsheng Lin
Date: Tue Jun 27 2017 - 20:33:54 EST
Hi, Madalin
On 2017/6/27 19:48, Madalin-cristian Bucur wrote:
>> -----Original Message-----
>> From: netdev-owner@xxxxxxxxxxxxxxx [mailto:netdev-owner@xxxxxxxxxxxxxxx]
>> On Behalf Of Lin Yun Sheng
>> Sent: Tuesday, June 27, 2017 2:01 PM
>> To: davem@xxxxxxxxxxxxx; andrew@xxxxxxx; f.fainelli@xxxxxxxxx
>> Cc: huangdaode@xxxxxxxxxxxxx; xuwei5@xxxxxxxxxxxxx;
>> liguozhu@xxxxxxxxxxxxx; Yisen.Zhuang@xxxxxxxxxx;
>> gabriele.paoloni@xxxxxxxxxx; john.garry@xxxxxxxxxx; linuxarm@xxxxxxxxxx;
>> yisen.zhuang@xxxxxxxxxx; salil.mehta@xxxxxxxxxx; lipeng321@xxxxxxxxxx;
>> tremyfr@xxxxxxxxx; netdev@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx
>> Subject: [PATCH NET V6 1/2] net: phy: Add phy loopback support in net phy
>> framework
>>
>> This patch add set_loopback in phy_driver, which is used by Mac
>> driver to enable or disable a phy. it also add a generic
>> genphy_loopback function, which use BMCR loopback bit to enable
>> or disable a phy.
>
> "disable a phy" or disable the PHY loopback function?
It should be disable the PHY loopback function, thanks for pointing out.
>
>> @@ -1123,6 +1123,39 @@ int phy_resume(struct phy_device *phydev)
>> }
>> EXPORT_SYMBOL(phy_resume);
>>
>> +int phy_loopback(struct phy_device *phydev, bool enable)
>> +{
>> + struct phy_driver *phydrv = to_phy_driver(phydev->mdio.dev.driver);
>> + int ret = 0;
>> +
>> + mutex_lock(&phydev->lock);
>> +
>> + if (enable && phydev->loopback_enabled) {
>> + ret = -EBUSY;
>> + goto out;
>> + }
>> +
>> + if (!enable && !phydev->loopback_enabled) {
>> + ret = -EINVAL;
>> + goto out;
>> + }
>> +
>
> if (enable == phydev->loopback_enabled)
One if statement don't work here, it returns different error code.
>
>> + if (phydev->drv && phydrv->set_loopback)
>> + ret = phydrv->set_loopback(phydev, enable);
>> + else
>> + ret = -EOPNOTSUPP;
>> +
>> + if (ret)
>> + goto out;
>> +
>> + phydev->loopback_enabled = enable;
>> +
>> +out:
>> + mutex_unlock(&phydev->lock);
>> + return ret;
>> +}
>> +EXPORT_SYMBOL(phy_loopback);
>> +
>
Best Regards
Yunsheng