2014-02-18 12:17:09

by Ben Dooks

[permalink] [raw]
Subject: [PATCH v2] of_mdio: fix phy interrupt passing

The of_mdiobus_register_phy() is not setting phy->irq thus causing
some drivers to incorrectly assume that the PHY does not have an
IRQ associated with it. Not only do some drivers report no IRQ
they do not install an interrupt handler for the PHY.

Simplify the code setting irq and set the phy->irq at the same
time so that we cover the following issues, which should cover
all the cases the code will find:

- Set phy->irq if node has irq property and mdio->irq is NULL
- Set phy->irq if node has no irq and mdio->irq is not NULL
- Leave phy->irq as PHY_POLL default if none of the above

This fixes the issue:
net eth0: attached PHY 1 (IRQ -1) to driver Micrel KSZ8041RNLI

to the correct:
net eth0: attached PHY 1 (IRQ 416) to driver Micrel KSZ8041RNLI

Signed-off-by: Ben Dooks <[email protected]>

---
Since v1:
- Updated phy->irq setting code
- Deal with issue if mdio->irq array NULL

Notes:

It was discussed if this should be two patches, but we end up
making enough changes in #2 the same area as #1 means that we
basically rewrite #1 in #2. So keep it as 1 patch.
---
drivers/of/of_mdio.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 875b7b6..46d95fc 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -44,7 +44,7 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi
{
struct phy_device *phy;
bool is_c45;
- int rc, prev_irq;
+ int rc;
u32 max_speed = 0;

is_c45 = of_device_is_compatible(child,
@@ -54,12 +54,14 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi
if (!phy || IS_ERR(phy))
return 1;

- if (mdio->irq) {
- prev_irq = mdio->irq[addr];
- mdio->irq[addr] =
- irq_of_parse_and_map(child, 0);
- if (!mdio->irq[addr])
- mdio->irq[addr] = prev_irq;
+ rc = irq_of_parse_and_map(child, 0);
+ if (rc > 0) {
+ phy->irq = rc;
+ if (mdio->irq)
+ mdio->irq[addr] = rc;
+ } else {
+ if (mdio->irq)
+ phy->irq = mdio->irq[addr];
}

/* Associate the OF node with the device structure so it
--
1.8.5.3


2014-02-18 14:48:28

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH v2] of_mdio: fix phy interrupt passing

Hello.

On 18-02-2014 16:16, Ben Dooks wrote:

> The of_mdiobus_register_phy() is not setting phy->irq thus causing
> some drivers to incorrectly assume that the PHY does not have an
> IRQ associated with it. Not only do some drivers report no IRQ
> they do not install an interrupt handler for the PHY.

> Simplify the code setting irq and set the phy->irq at the same
> time so that we cover the following issues, which should cover
> all the cases the code will find:

> - Set phy->irq if node has irq property and mdio->irq is NULL
> - Set phy->irq if node has no irq and mdio->irq is not NULL
> - Leave phy->irq as PHY_POLL default if none of the above

> This fixes the issue:
> net eth0: attached PHY 1 (IRQ -1) to driver Micrel KSZ8041RNLI

> to the correct:
> net eth0: attached PHY 1 (IRQ 416) to driver Micrel KSZ8041RNLI

> Signed-off-by: Ben Dooks <[email protected]>

> ---
> Since v1:
> - Updated phy->irq setting code
> - Deal with issue if mdio->irq array NULL

> Notes:

> It was discussed if this should be two patches, but we end up
> making enough changes in #2 the same area as #1 means that we
> basically rewrite #1 in #2. So keep it as 1 patch.
> ---
> drivers/of/of_mdio.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)

> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
> index 875b7b6..46d95fc 100644
> --- a/drivers/of/of_mdio.c
> +++ b/drivers/of/of_mdio.c
[...]
> @@ -54,12 +54,14 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi
> if (!phy || IS_ERR(phy))
> return 1;
>
> - if (mdio->irq) {
> - prev_irq = mdio->irq[addr];
> - mdio->irq[addr] =
> - irq_of_parse_and_map(child, 0);
> - if (!mdio->irq[addr])
> - mdio->irq[addr] = prev_irq;
> + rc = irq_of_parse_and_map(child, 0);
> + if (rc > 0) {
> + phy->irq = rc;
> + if (mdio->irq)
> + mdio->irq[addr] = rc;
> + } else {
> + if (mdio->irq)

You could write that as *else if* and save a line of code...

> + phy->irq = mdio->irq[addr];
> }

WBR, Sergei

2014-02-18 16:15:57

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH v2] of_mdio: fix phy interrupt passing

On Tue, 18 Feb 2014 12:16:58 +0000, Ben Dooks <[email protected]> wrote:
> The of_mdiobus_register_phy() is not setting phy->irq thus causing
> some drivers to incorrectly assume that the PHY does not have an
> IRQ associated with it. Not only do some drivers report no IRQ
> they do not install an interrupt handler for the PHY.
>
> Simplify the code setting irq and set the phy->irq at the same
> time so that we cover the following issues, which should cover
> all the cases the code will find:
>
> - Set phy->irq if node has irq property and mdio->irq is NULL
> - Set phy->irq if node has no irq and mdio->irq is not NULL
> - Leave phy->irq as PHY_POLL default if none of the above
>
> This fixes the issue:
> net eth0: attached PHY 1 (IRQ -1) to driver Micrel KSZ8041RNLI
>
> to the correct:
> net eth0: attached PHY 1 (IRQ 416) to driver Micrel KSZ8041RNLI
>
> Signed-off-by: Ben Dooks <[email protected]>

Looks okay to me

Reviewed-by: Grant Likely <[email protected]>

>
> ---
> Since v1:
> - Updated phy->irq setting code
> - Deal with issue if mdio->irq array NULL
>
> Notes:
>
> It was discussed if this should be two patches, but we end up
> making enough changes in #2 the same area as #1 means that we
> basically rewrite #1 in #2. So keep it as 1 patch.
> ---
> drivers/of/of_mdio.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
> index 875b7b6..46d95fc 100644
> --- a/drivers/of/of_mdio.c
> +++ b/drivers/of/of_mdio.c
> @@ -44,7 +44,7 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi
> {
> struct phy_device *phy;
> bool is_c45;
> - int rc, prev_irq;
> + int rc;
> u32 max_speed = 0;
>
> is_c45 = of_device_is_compatible(child,
> @@ -54,12 +54,14 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi
> if (!phy || IS_ERR(phy))
> return 1;
>
> - if (mdio->irq) {
> - prev_irq = mdio->irq[addr];
> - mdio->irq[addr] =
> - irq_of_parse_and_map(child, 0);
> - if (!mdio->irq[addr])
> - mdio->irq[addr] = prev_irq;
> + rc = irq_of_parse_and_map(child, 0);
> + if (rc > 0) {
> + phy->irq = rc;
> + if (mdio->irq)
> + mdio->irq[addr] = rc;
> + } else {
> + if (mdio->irq)
> + phy->irq = mdio->irq[addr];
> }
>
> /* Associate the OF node with the device structure so it
> --
> 1.8.5.3
>

2014-02-18 19:29:16

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH v2] of_mdio: fix phy interrupt passing

Hello.

On 02/18/2014 03:16 PM, Ben Dooks wrote:

> The of_mdiobus_register_phy() is not setting phy->irq thus causing
> some drivers to incorrectly assume that the PHY does not have an
> IRQ associated with it. Not only do some drivers report no IRQ
> they do not install an interrupt handler for the PHY.

> Simplify the code setting irq and set the phy->irq at the same
> time so that we cover the following issues, which should cover
> all the cases the code will find:

> - Set phy->irq if node has irq property and mdio->irq is NULL
> - Set phy->irq if node has no irq and mdio->irq is not NULL
> - Leave phy->irq as PHY_POLL default if none of the above

> This fixes the issue:
> net eth0: attached PHY 1 (IRQ -1) to driver Micrel KSZ8041RNLI

> to the correct:
> net eth0: attached PHY 1 (IRQ 416) to driver Micrel KSZ8041RNLI

> Signed-off-by: Ben Dooks <[email protected]>

[...]

> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
> index 875b7b6..46d95fc 100644
> --- a/drivers/of/of_mdio.c
> +++ b/drivers/of/of_mdio.c
[...]
> @@ -54,12 +54,14 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi
> if (!phy || IS_ERR(phy))
> return 1;
>
> - if (mdio->irq) {
> - prev_irq = mdio->irq[addr];
> - mdio->irq[addr] =
> - irq_of_parse_and_map(child, 0);
> - if (!mdio->irq[addr])
> - mdio->irq[addr] = prev_irq;
> + rc = irq_of_parse_and_map(child, 0);
> + if (rc > 0) {
> + phy->irq = rc;
> + if (mdio->irq)
> + mdio->irq[addr] = rc;
> + } else {
> + if (mdio->irq)
> + phy->irq = mdio->irq[addr];

I have now looked thru the of_mdio.c code and the code it calls.
This case seems to be cared about by phy_device_create() called earlier
via get_phy_device() call just above this hunk; in any case the value will be
PHY_POLL. I don't think this branch is needed at all.

WBR, Sergei

2014-02-18 23:13:26

by David Miller

[permalink] [raw]
Subject: Re: [PATCH v2] of_mdio: fix phy interrupt passing

From: Grant Likely <[email protected]>
Date: Tue, 18 Feb 2014 16:15:51 +0000

> On Tue, 18 Feb 2014 12:16:58 +0000, Ben Dooks <[email protected]> wrote:
>> The of_mdiobus_register_phy() is not setting phy->irq thus causing
>> some drivers to incorrectly assume that the PHY does not have an
>> IRQ associated with it. Not only do some drivers report no IRQ
>> they do not install an interrupt handler for the PHY.
>>
>> Simplify the code setting irq and set the phy->irq at the same
>> time so that we cover the following issues, which should cover
>> all the cases the code will find:
>>
>> - Set phy->irq if node has irq property and mdio->irq is NULL
>> - Set phy->irq if node has no irq and mdio->irq is not NULL
>> - Leave phy->irq as PHY_POLL default if none of the above
>>
>> This fixes the issue:
>> net eth0: attached PHY 1 (IRQ -1) to driver Micrel KSZ8041RNLI
>>
>> to the correct:
>> net eth0: attached PHY 1 (IRQ 416) to driver Micrel KSZ8041RNLI
>>
>> Signed-off-by: Ben Dooks <[email protected]>
>
> Looks okay to me
>
> Reviewed-by: Grant Likely <[email protected]>

Applied, thanks.

2014-02-19 13:27:38

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH v2] of_mdio: fix phy interrupt passing

Hello.

On 19-02-2014 3:13, David Miller wrote:

>>> The of_mdiobus_register_phy() is not setting phy->irq thus causing
>>> some drivers to incorrectly assume that the PHY does not have an
>>> IRQ associated with it. Not only do some drivers report no IRQ
>>> they do not install an interrupt handler for the PHY.

>>> Simplify the code setting irq and set the phy->irq at the same
>>> time so that we cover the following issues, which should cover
>>> all the cases the code will find:

>>> - Set phy->irq if node has irq property and mdio->irq is NULL
>>> - Set phy->irq if node has no irq and mdio->irq is not NULL
>>> - Leave phy->irq as PHY_POLL default if none of the above

>>> This fixes the issue:
>>> net eth0: attached PHY 1 (IRQ -1) to driver Micrel KSZ8041RNLI

>>> to the correct:
>>> net eth0: attached PHY 1 (IRQ 416) to driver Micrel KSZ8041RNLI

>>> Signed-off-by: Ben Dooks <[email protected]>

>> Looks okay to me

>> Reviewed-by: Grant Likely <[email protected]>

> Applied, thanks.

So, you decided to ignore my comment about unneeded *else* branch?

WBR, Sergei

2014-02-19 17:54:36

by David Miller

[permalink] [raw]
Subject: Re: [PATCH v2] of_mdio: fix phy interrupt passing

From: Sergei Shtylyov <[email protected]>
Date: Wed, 19 Feb 2014 17:27:39 +0400

> So, you decided to ignore my comment about unneeded *else* branch?

Not ignored, just figured that a follow-up patch could fix it.