Re: [PATCH net-next 1/4] drivers: net: xgene-v2: Add MDIO support

2017-03-21 Thread Iyappan Subramanian
On Tue, Mar 21, 2017 at 1:35 PM, Andrew Lunn  wrote:
>> @@ -511,9 +512,9 @@ static int xge_close(struct net_device *ndev)
>>  {
>>   struct xge_pdata *pdata = netdev_priv(ndev);
>>
>> - netif_carrier_off(ndev);
>>   netif_stop_queue(ndev);
>>   xge_mac_disable(pdata);
>> + phy_stop(ndev->phydev);
>>
>>   xge_intr_disable(pdata);
>>   xge_free_irq(ndev);
>> @@ -683,9 +684,14 @@ static int xge_probe(struct platform_device *pdev)
>>   if (ret)
>>   goto err;
>>
>> + spin_lock_init(>mdio_lock);
>> +
>
> ...
>
>> +static int xge_mdio_write(struct mii_bus *bus, int phy_id, int reg, u16 
>> data)
>> +{
>> + struct xge_pdata *pdata = bus->priv;
>> + u32 done, val = 0;
>> + u8 wait = 10;
>> + int ret = 0;
>> +
>> + spin_lock(>mdio_lock);
>> +
>> + SET_REG_BITS(, PHY_ADDR, phy_id);
>> + SET_REG_BITS(, REG_ADDR, reg);
>> + xge_wr_csr(pdata, MII_MGMT_ADDRESS, val);
>> +
>> + xge_wr_csr(pdata, MII_MGMT_CONTROL, data);
>> + do {
>> + usleep_range(5, 10);
>> + done = xge_rd_csr(pdata, MII_MGMT_INDICATORS);
>> + } while ((done & MII_MGMT_BUSY) && wait--);
>> +
>> + if (done & MII_MGMT_BUSY) {
>> + dev_err(>dev, "MII_MGMT write failed\n");
>> + ret = -ETIMEDOUT;
>> + }
>> +
>> + spin_unlock(>mdio_lock);
>> +
>> + return ret;
>> +}
>> +
>> +static int xge_mdio_read(struct mii_bus *bus, int phy_id, int reg)
>> +{
>> + struct xge_pdata *pdata = bus->priv;
>> + u32 data, done, val = 0;
>> + u8 wait = 10;
>> +
>> + spin_lock(>mdio_lock);
>> +
>
> Hi Iyappan
>
> Please could you explain what this lock is protecting which the
> mii_bus mdio_lock in mdio_bus.c is not protecting?

Hi Keyur,

Please could you explain what this lock is protecting which the
mii_bus mdio_lock in mdio_bus.c is not protecting?

I agree with him.  Actually there is a mutex on mdio_bus.  So the mdio
bus read and write are locked.  we don't need the lock.

Do you agree ?


>
> Thanks
> Andrew


Re: [PATCH net-next 1/4] drivers: net: xgene-v2: Add MDIO support

2017-03-21 Thread Andrew Lunn
> @@ -511,9 +512,9 @@ static int xge_close(struct net_device *ndev)
>  {
>   struct xge_pdata *pdata = netdev_priv(ndev);
>  
> - netif_carrier_off(ndev);
>   netif_stop_queue(ndev);
>   xge_mac_disable(pdata);
> + phy_stop(ndev->phydev);
>  
>   xge_intr_disable(pdata);
>   xge_free_irq(ndev);
> @@ -683,9 +684,14 @@ static int xge_probe(struct platform_device *pdev)
>   if (ret)
>   goto err;
>  
> + spin_lock_init(>mdio_lock);
> +

...

> +static int xge_mdio_write(struct mii_bus *bus, int phy_id, int reg, u16 data)
> +{
> + struct xge_pdata *pdata = bus->priv;
> + u32 done, val = 0;
> + u8 wait = 10;
> + int ret = 0;
> +
> + spin_lock(>mdio_lock);
> +
> + SET_REG_BITS(, PHY_ADDR, phy_id);
> + SET_REG_BITS(, REG_ADDR, reg);
> + xge_wr_csr(pdata, MII_MGMT_ADDRESS, val);
> +
> + xge_wr_csr(pdata, MII_MGMT_CONTROL, data);
> + do {
> + usleep_range(5, 10);
> + done = xge_rd_csr(pdata, MII_MGMT_INDICATORS);
> + } while ((done & MII_MGMT_BUSY) && wait--);
> +
> + if (done & MII_MGMT_BUSY) {
> + dev_err(>dev, "MII_MGMT write failed\n");
> + ret = -ETIMEDOUT;
> + }
> +
> + spin_unlock(>mdio_lock);
> +
> + return ret;
> +}
> +
> +static int xge_mdio_read(struct mii_bus *bus, int phy_id, int reg)
> +{
> + struct xge_pdata *pdata = bus->priv;
> + u32 data, done, val = 0;
> + u8 wait = 10;
> +
> + spin_lock(>mdio_lock);
> +

Hi Iyappan

Please could you explain what this lock is protecting which the
mii_bus mdio_lock in mdio_bus.c is not protecting?

Thanks
Andrew