2018-04-06 14:07:21

by Esben Haabendal

[permalink] [raw]
Subject: [PATCH] dp83640: Ensure against premature access to PHY registers after reset

From: Esben Haabendal <[email protected]>

Signed-off-by: Esben Haabendal <[email protected]>
---
drivers/net/phy/dp83640.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index 654f42d00092..48403170096a 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -1207,6 +1207,22 @@ static void dp83640_remove(struct phy_device *phydev)
kfree(dp83640);
}

+static int dp83640_soft_reset(struct phy_device *phydev)
+{
+ int ret;
+
+ ret = genphy_soft_reset(phydev);
+ if (ret < 0)
+ return ret;
+
+ /* From DP83640 datasheet: "Software driver code must wait 3 us
+ * following a software reset before allowing further serial MII
+ * operations with the DP83640." */
+ udelay(3);
+
+ return 0;
+}
+
static int dp83640_config_init(struct phy_device *phydev)
{
struct dp83640_private *dp83640 = phydev->priv;
@@ -1501,6 +1517,7 @@ static struct phy_driver dp83640_driver = {
.flags = PHY_HAS_INTERRUPT,
.probe = dp83640_probe,
.remove = dp83640_remove,
+ .soft_reset = dp83640_soft_reset,
.config_init = dp83640_config_init,
.ack_interrupt = dp83640_ack_interrupt,
.config_intr = dp83640_config_intr,
--
2.16.3



2018-04-06 14:15:33

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH] dp83640: Ensure against premature access to PHY registers after reset

On Fri, Apr 06, 2018 at 04:05:40PM +0200, Esben Haabendal wrote:
> From: Esben Haabendal <[email protected]>
>
> Signed-off-by: Esben Haabendal <[email protected]>
> ---
> drivers/net/phy/dp83640.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
> index 654f42d00092..48403170096a 100644
> --- a/drivers/net/phy/dp83640.c
> +++ b/drivers/net/phy/dp83640.c
> @@ -1207,6 +1207,22 @@ static void dp83640_remove(struct phy_device *phydev)
> kfree(dp83640);
> }
>
> +static int dp83640_soft_reset(struct phy_device *phydev)
> +{
> + int ret;
> +
> + ret = genphy_soft_reset(phydev);
> + if (ret < 0)
> + return ret;
> +
> + /* From DP83640 datasheet: "Software driver code must wait 3 us
> + * following a software reset before allowing further serial MII
> + * operations with the DP83640." */
> + udelay(3);

Hi Esben

The accuracy of udelay() is not guaranteed. So you probably want to be
a bit pessimistic, and use 10.

Andrew

2018-04-06 15:15:05

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] dp83640: Ensure against premature access to PHY registers after reset

From: Andrew Lunn <[email protected]>
Date: Fri, 6 Apr 2018 16:14:10 +0200

> On Fri, Apr 06, 2018 at 04:05:40PM +0200, Esben Haabendal wrote:
>> From: Esben Haabendal <[email protected]>
>>
>> Signed-off-by: Esben Haabendal <[email protected]>
>> ---
>> drivers/net/phy/dp83640.c | 17 +++++++++++++++++
>> 1 file changed, 17 insertions(+)
>>
>> diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
>> index 654f42d00092..48403170096a 100644
>> --- a/drivers/net/phy/dp83640.c
>> +++ b/drivers/net/phy/dp83640.c
>> @@ -1207,6 +1207,22 @@ static void dp83640_remove(struct phy_device *phydev)
>> kfree(dp83640);
>> }
>>
>> +static int dp83640_soft_reset(struct phy_device *phydev)
>> +{
>> + int ret;
>> +
>> + ret = genphy_soft_reset(phydev);
>> + if (ret < 0)
>> + return ret;
>> +
>> + /* From DP83640 datasheet: "Software driver code must wait 3 us
>> + * following a software reset before allowing further serial MII
>> + * operations with the DP83640." */
>> + udelay(3);
>
> Hi Esben
>
> The accuracy of udelay() is not guaranteed. So you probably want to be
> a bit pessimistic, and use 10.

Agreed.

2018-04-06 17:11:24

by Esben Haabendal

[permalink] [raw]
Subject: Re: [PATCH] dp83640: Ensure against premature access to PHY registers after reset

David Miller <[email protected]> writes:

> From: Andrew Lunn <[email protected]>
> Date: Fri, 6 Apr 2018 16:14:10 +0200
>
>> On Fri, Apr 06, 2018 at 04:05:40PM +0200, Esben Haabendal wrote:
>>> From: Esben Haabendal <[email protected]>
>>>
>>> Signed-off-by: Esben Haabendal <[email protected]>
>>> ---
>>> drivers/net/phy/dp83640.c | 17 +++++++++++++++++
>>> 1 file changed, 17 insertions(+)
>>>
>>> diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
>>> index 654f42d00092..48403170096a 100644
>>> --- a/drivers/net/phy/dp83640.c
>>> +++ b/drivers/net/phy/dp83640.c
>>> @@ -1207,6 +1207,22 @@ static void dp83640_remove(struct phy_device *phydev)
>>> kfree(dp83640);
>>> }
>>>
>>> +static int dp83640_soft_reset(struct phy_device *phydev)
>>> +{
>>> + int ret;
>>> +
>>> + ret = genphy_soft_reset(phydev);
>>> + if (ret < 0)
>>> + return ret;
>>> +
>>> + /* From DP83640 datasheet: "Software driver code must wait 3 us
>>> + * following a software reset before allowing further serial MII
>>> + * operations with the DP83640." */
>>> + udelay(3);
>>
>> Hi Esben
>>
>> The accuracy of udelay() is not guaranteed. So you probably want to be
>> a bit pessimistic, and use 10.

Ok, will do.

/Esben

2018-04-06 17:13:36

by Esben Haabendal

[permalink] [raw]
Subject: [PATCH v2] dp83640: Ensure against premature access to PHY registers after reset

From: Esben Haabendal <[email protected]>

Signed-off-by: Esben Haabendal <[email protected]>
---
drivers/net/phy/dp83640.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index 654f42d00092..a6c87793d899 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -1207,6 +1207,23 @@ static void dp83640_remove(struct phy_device *phydev)
kfree(dp83640);
}

+static int dp83640_soft_reset(struct phy_device *phydev)
+{
+ int ret;
+
+ ret = genphy_soft_reset(phydev);
+ if (ret < 0)
+ return ret;
+
+ /* From DP83640 datasheet: "Software driver code must wait 3 us
+ * following a software reset before allowing further serial MII
+ * operations with the DP83640."
+ */
+ udelay(10); /* Taking udelay inaccuracy into account */
+
+ return 0;
+}
+
static int dp83640_config_init(struct phy_device *phydev)
{
struct dp83640_private *dp83640 = phydev->priv;
@@ -1501,6 +1518,7 @@ static struct phy_driver dp83640_driver = {
.flags = PHY_HAS_INTERRUPT,
.probe = dp83640_probe,
.remove = dp83640_remove,
+ .soft_reset = dp83640_soft_reset,
.config_init = dp83640_config_init,
.ack_interrupt = dp83640_ack_interrupt,
.config_intr = dp83640_config_intr,
--
2.16.3


2018-04-06 17:27:15

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH v2] dp83640: Ensure against premature access to PHY registers after reset

On Fri, Apr 06, 2018 at 07:08:44PM +0200, Esben Haabendal wrote:
> From: Esben Haabendal <[email protected]>

Hi Esben

It it good to have some form of commit message. Something like:

The datasheet specifies a 3uS pause after performing a software
reset. The default implementation of genphy_soft_reset() does not
provide this, so implement soft_reset with the needed pause.


With that, or something similar added:

Reviewed-by: Andrew Lunn <[email protected]>

Andrew

2018-04-08 21:00:01

by Esben Haabendal

[permalink] [raw]
Subject: [PATCH v3] dp83640: Ensure against premature access to PHY registers after reset

From: Esben Haabendal <[email protected]>

The datasheet specifies a 3uS pause after performing a software
reset. The default implementation of genphy_soft_reset() does not
provide this, so implement soft_reset with the needed pause.

Signed-off-by: Esben Haabendal <[email protected]>
Reviewed-by: Andrew Lunn <[email protected]>
---
drivers/net/phy/dp83640.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index 654f42d00092..a6c87793d899 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -1207,6 +1207,23 @@ static void dp83640_remove(struct phy_device *phydev)
kfree(dp83640);
}

+static int dp83640_soft_reset(struct phy_device *phydev)
+{
+ int ret;
+
+ ret = genphy_soft_reset(phydev);
+ if (ret < 0)
+ return ret;
+
+ /* From DP83640 datasheet: "Software driver code must wait 3 us
+ * following a software reset before allowing further serial MII
+ * operations with the DP83640."
+ */
+ udelay(10); /* Taking udelay inaccuracy into account */
+
+ return 0;
+}
+
static int dp83640_config_init(struct phy_device *phydev)
{
struct dp83640_private *dp83640 = phydev->priv;
@@ -1501,6 +1518,7 @@ static struct phy_driver dp83640_driver = {
.flags = PHY_HAS_INTERRUPT,
.probe = dp83640_probe,
.remove = dp83640_remove,
+ .soft_reset = dp83640_soft_reset,
.config_init = dp83640_config_init,
.ack_interrupt = dp83640_ack_interrupt,
.config_intr = dp83640_config_intr,
--
2.16.3


2018-04-09 00:18:19

by David Miller

[permalink] [raw]
Subject: Re: [PATCH v3] dp83640: Ensure against premature access to PHY registers after reset

From: Esben Haabendal <[email protected]>
Date: Sun, 8 Apr 2018 22:17:01 +0200

> From: Esben Haabendal <[email protected]>
>
> The datasheet specifies a 3uS pause after performing a software
> reset. The default implementation of genphy_soft_reset() does not
> provide this, so implement soft_reset with the needed pause.
>
> Signed-off-by: Esben Haabendal <[email protected]>
> Reviewed-by: Andrew Lunn <[email protected]>

Applied, thank you.