of_mdio: fix phy interrupt passing
Subsystems (4)
PATCH 1/1 of_mdio: fix phy interrupt passing
The of_mdiobus_register_phy() is not setting phy->irq this causing some drivers to incorrectly assume that the PHY does not have an IRQ associated with it or install an interrupt handler for the PHY.
Simplify the code setting irq and set the phy->irq at the same time so that the case if mdio->irq is not NULL is easier to read.
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
--- drivers/of/of_mdio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/of/of_mdio.c +6 -6
@@ -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,
@@ -55,11 +55,11 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chireturn 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 ) { + mdio->irq[addr] = rc; + phy->irq = rc; + } }/* Associate the OF node with the device structure so it
Signature · 6 lines
1.8.5.3 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Ben,
2014-02-17 8:29 GMT-08:00 Ben Dooks <[email protected]>:
Quoted 7 lines
The
of_mdiobus_register_phy()is not settingphy->irqthis causing some drivers to incorrectly assume that the PHY does not have an IRQ associated with it or install an interrupt handler for the PHY.Simplify the code setting irq and set the
phy->irqat the same time so that the case ifmdio->irqis not NULL is easier to read.
The real bug fix, which is not properly explained here, is that irq_of_parse_and_map() should return values > 0 when the interrupt is valid, so this makes me wonder why we are not propagating the return value from irq_of_parse_and_map() in case the call to of_irq_parse_one() does return something non-zero?
Other than that, I agree with the resolution, but it deserves a better commit message, and eventually doing this in two steps:
- first fix the bug by changing the if (!mdio->irq[addr]) into a if (mdio->irq[addr] <= 0)
- second submit a patch which cleanups the assignment
Quoted 49 lines
This fixes the issue:
net eth0: attached PHY 1 (IRQ -1) to driver Micrel KSZ8041RNLIto the correct:
net eth0: attached PHY 1 (IRQ 416) to driver Micrel KSZ8041RNLISigned-off-by Ben Dooks <[email protected]>--- drivers/of/of_mdio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/of/of_mdio.c +6
-7@@ -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,@@ -55,11 +55,11 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chireturn 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 ) { + mdio->irq[addr] = rc; + phy->irq = rc; + } }/* Associate the OF node with the device structure so it -- 1.8.5.3
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Florian
Quoted 8 lines · Florian Fainelli
Hi Ben,
2014-02-17 8:29 GMT-08:00 Ben Dooks <[email protected]>:
Quoted 5 lines
The
of_mdiobus_register_phy()is not settingphy->irqthis causing some drivers to incorrectly assume that the PHY does not have an IRQ associated with it or install an interrupt handler for the PHY.
Quoted 8 lines
Quoted 2 lines
Simplify the code setting irq and set the
phy->irqat the same time so that the case ifmdio->irqis not NULL is easier to read.The real bug fix, which is not properly explained here, is that
irq_of_parse_and_map()should return values > 0 when the interrupt is valid, so this makes me wonder why we are not propagating the return value fromirq_of_parse_and_map()in case the call toof_irq_parse_one()does return something non-zero?
No, the first issue is phy->dev never gets set, which causes the issue. The cleanup was added as it seemed easier to put it in with this.
I think phy->irq is already initialised to PHY_POLL and thus there is no need to set phy->irq if the irq_of_parse_and_map() fails.
Signature · 2 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius
2014-02-17 9:42 GMT-08:00 Ben Dooks <[email protected]>:
Quoted 22 lines · Florian Fainelli
Quoted 14 lines
Hi Ben,
2014-02-17 8:29 GMT-08:00 Ben Dooks <[email protected]>:
Quoted 8 lines
The
of_mdiobus_register_phy()is not settingphy->irqthis causing some drivers to incorrectly assume that the PHY does not have an IRQ associated with it or install an interrupt handler for the PHY.Simplify the code setting irq and set the
phy->irqat the same time so that the case ifmdio->irqis not NULL is easier to read.Quoted 5 lines
The real bug fix, which is not properly explained here, is that
irq_of_parse_and_map()should return values > 0 when the interrupt is valid, so this makes me wonder why we are not propagating the return value fromirq_of_parse_and_map()in case the call toof_irq_parse_one()does return something non-zero?
Quoted 3 lines
No, the first issue is
phy->devnever gets set, which causes the issue. The cleanup was added as it seemed easier to put it in with this.
Ok, that really needs to be mentioned in the commit message, even being quite familiar (and possibly dumb too) with the code, I could not figure this out by reading your patch.
Quoted 3 lines
I think
phy->irqis already initialised toPHY_POLLand thus there is no need to setphy->irqif theirq_of_parse_and_map()fails.
That is correct, the reason why I introduced 7d97637 ("net: of_mdio:
do not overwrite PHY interrupt configuration") was that you are also allowed to change the irq type before calling into of_mdiobus_register(), so we want to preserve other irq values being set here, such as PHY_IGNORE_INTERRUPT. Your patch does take care of that since it only overrides the irq in case we could parse it.
Signature · 1 line
Florian
Quoted 8 lines · Florian Fainelli
Hi Ben,
2014-02-17 8:29 GMT-08:00 Ben Dooks <[email protected]>:
Quoted 5 lines
The
of_mdiobus_register_phy()is not settingphy->irqthis causing some drivers to incorrectly assume that the PHY does not have an IRQ associated with it or install an interrupt handler for the PHY.
Quoted 8 lines
Quoted 2 lines
Simplify the code setting irq and set the
phy->irqat the same time so that the case ifmdio->irqis not NULL is easier to read.The real bug fix, which is not properly explained here, is that
irq_of_parse_and_map()should return values > 0 when the interrupt is valid, so this makes me wonder why we are not propagating the return value fromirq_of_parse_and_map()in case the call toof_irq_parse_one()does return something non-zero?
rc = irq_of_parse_and_map(child, 0);
if (rc > 0) {
mdio->irq[addr] = rc;
phy->irq = rc;
}Unfortunately we do not get any idea of what error went wrong when doing this, all we get it 0 on failure. So we cannot tell if the problem was due to no interrupt being there or there was an interrupt and it could not be parsed properly.
The best we can do is assume that the PHY is happy with being polled and the specific driver will error out if it expects to be able to work with an interrupt.
If we error out, we may end up stopping any PHYs where there is no interrupt available from working. Also, if we fail to parse then we can generally fall back to polling.
Signature · 2 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius
Quoted 35 lines · Florian Fainelli
2014-02-17 9:42 GMT-08:00 Ben Dooks <[email protected]>:
Quoted 22 lines · Florian Fainelli
Quoted 14 lines
Hi Ben,
2014-02-17 8:29 GMT-08:00 Ben Dooks <[email protected]>:
Quoted 8 lines
The
of_mdiobus_register_phy()is not settingphy->irqthis causing some drivers to incorrectly assume that the PHY does not have an IRQ associated with it or install an interrupt handler for the PHY.Simplify the code setting irq and set the
phy->irqat the same time so that the case ifmdio->irqis not NULL is easier to read.Quoted 5 lines
The real bug fix, which is not properly explained here, is that
irq_of_parse_and_map()should return values > 0 when the interrupt is valid, so this makes me wonder why we are not propagating the return value fromirq_of_parse_and_map()in case the call toof_irq_parse_one()does return something non-zero?Quoted 3 lines
No, the first issue is
phy->devnever gets set, which causes the issue. The cleanup was added as it seemed easier to put it in with this.Ok, that really needs to be mentioned in the commit message, even being quite familiar (and possibly dumb too) with the code, I could not figure this out by reading your patch.
Quoted 3 lines
I think
phy->irqis already initialised toPHY_POLLand thus there is no need to setphy->irqif theirq_of_parse_and_map()fails.
Quoted 6 lines
That is correct, the reason why I introduced 7d97637 ("net:
of_mdio:
do not overwrite PHY interrupt configuration") was that you are also allowed to change the irq type before calling intoof_mdiobus_register(), so we want to preserve other irq values being set here, such asPHY_IGNORE_INTERRUPT. Your patch does take care of that since it only overrides the irq in case we could parse it.
Ok, the first sentence has a spell of thus, but does refer to phy->irq being the problem we are looking to fix in this patch.
Signature · 2 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius
Quoted 33 lines · Ben Dooks
The
of_mdiobus_register_phy()is not settingphy->irqthis causing some drivers to incorrectly assume that the PHY does not have an IRQ associated with it or install an interrupt handler for the PHY.Simplify the code setting irq and set the
phy->irqat the same time so that the case ifmdio->irqis not NULL is easier to read.This fixes the issue:
net eth0: attached PHY 1 (IRQ -1) to driver Micrel KSZ8041RNLIto the correct:
net eth0: attached PHY 1 (IRQ 416) to driver Micrel KSZ8041RNLISigned-off-by Ben Dooks <[email protected]>--- drivers/of/of_mdio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/of/of_mdio.c +1
-1@@ -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,
drivers/of/of_mdio.c static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi · line 62
Quoted 8 lines
drivers/of/of_mdio.c +0
-5@@ -55,11 +55,11 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chireturn 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;
I cannot for the life for me remeber why the code was structured that way. Your change is better.
drivers/of/of_mdio.c static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi · line 63
Quoted 6 lines
drivers/of/of_mdio.c +5
-0+ rc =irq_of_parse_and_map (child,0 ); +if (rc >0 ) { + mdio->irq[addr] = rc; + phy->irq = rc; + } }
The outer if is merely protecting against no irq array being allocated for the bus. Would not the following be better:
rc = irq_of_parse_and_map(child, 0);
if (rc > 0) {
phy->irq = rc;
if (mdio->irq)
mdio->irq[addr] = rc;
}g.
Quoted 56 lines · Grant Likely
Quoted 33 lines · Ben Dooks
The
of_mdiobus_register_phy()is not settingphy->irqthis causing some drivers to incorrectly assume that the PHY does not have an IRQ associated with it or install an interrupt handler for the PHY.Simplify the code setting irq and set the
phy->irqat the same time so that the case ifmdio->irqis not NULL is easier to read.This fixes the issue:
net eth0: attached PHY 1 (IRQ -1) to driver Micrel KSZ8041RNLIto the correct:
net eth0: attached PHY 1 (IRQ 416) to driver Micrel KSZ8041RNLISigned-off-by Ben Dooks <[email protected]>--- drivers/of/of_mdio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/of/of_mdio.c +1
-1@@ -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,drivers/of/of_mdio.c static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi · line 62
Quoted 8 lines
drivers/of/of_mdio.c +0
-5@@ -55,11 +55,11 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chireturn 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;I cannot for the life for me remeber why the code was structured that way. Your change is better.
drivers/of/of_mdio.c static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi · line 63
Quoted 6 lines
drivers/of/of_mdio.c +5
-0+ rc =irq_of_parse_and_map (child,0 ); +if (rc >0 ) { + mdio->irq[addr] = rc; + phy->irq = rc; + } }The outer if is merely protecting against no irq array being allocated for the bus. Would not the following be better:
Quoted 6 lines
rc = irq_of_parse_and_map(child, 0);
if (rc > 0) {
phy->irq = rc;
if (mdio->irq)
mdio->irq[addr] = rc;
}Thanks, that makes sense, although we've both failed to work out if mdio->irq is set, and rc <= 0 case, so:
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 think that covers all cases. This does rely on mdio->irq being initialised to PHY_POLL if allocated.
Once this is in, it may be easier then to not allocate mdio->irq for the OF case by default unless the driver registering the PHY knows it has the interrupt number(s) for the PHY already.
Signature · 2 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius
Quoted 72 lines · Ben Dooks
Quoted 56 lines · Grant Likely
Quoted 33 lines · Ben Dooks
The
of_mdiobus_register_phy()is not settingphy->irqthis causing some drivers to incorrectly assume that the PHY does not have an IRQ associated with it or install an interrupt handler for the PHY.Simplify the code setting irq and set the
phy->irqat the same time so that the case ifmdio->irqis not NULL is easier to read.This fixes the issue:
net eth0: attached PHY 1 (IRQ -1) to driver Micrel KSZ8041RNLIto the correct:
net eth0: attached PHY 1 (IRQ 416) to driver Micrel KSZ8041RNLISigned-off-by Ben Dooks <[email protected]>--- drivers/of/of_mdio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/of/of_mdio.c +1
-1@@ -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,drivers/of/of_mdio.c static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi · line 62
Quoted 8 lines
drivers/of/of_mdio.c +0
-5@@ -55,11 +55,11 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chireturn 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;I cannot for the life for me remeber why the code was structured that way. Your change is better.
drivers/of/of_mdio.c static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi · line 63
Quoted 6 lines
drivers/of/of_mdio.c +5
-0+ rc =irq_of_parse_and_map (child,0 ); +if (rc >0 ) { + mdio->irq[addr] = rc; + phy->irq = rc; + } }The outer if is merely protecting against no irq array being allocated for the bus. Would not the following be better:
Quoted 6 lines
rc = irq_of_parse_and_map(child, 0); if (rc > 0) { phy->irq = rc; if (mdio->irq) mdio->irq[addr] = rc; }Thanks, that makes sense, although we've both failed to work out if
mdio->irqis set, and rc <= 0 case, so:rc =
irq_of_parse_and_map(child, 0);
if (rc > 0) {
phy->irq= rc;
if (mdio->irq)
mdio->irq[addr] = rc;
Quoted 4 lines
} else {
if (mdio->irq)
phy->irq = mdio->irq[addr];
}Is this actually a valid thing to do? I think the only time mdio->irq[] is non-zero is when it is set to PHY_POLL. Is it valid to set phy->irq to PHY_POLL? I didn't think it was.
g.
Quoted 12 lines
I think that covers all cases. This does rely on
mdio->irqbeing initialised toPHY_POLLif allocated.Once this is in, it may be easier then to not allocate
mdio->irqfor the OF case by default unless the driver registering the PHY knows it has the interrupt number(s) for the PHY already.Signature · 2 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius
Hello.
Quoted 75 lines · Grant Likely
Quoted 65 lines
Quoted 55 lines · Ben Dooks
Quoted 33 lines
The
of_mdiobus_register_phy()is not settingphy->irqthis causing some drivers to incorrectly assume that the PHY does not have an IRQ associated with it or install an interrupt handler for the PHY.Simplify the code setting irq and set the
phy->irqat the same time so that the case ifmdio->irqis not NULL is easier to read.This fixes the issue:
net eth0: attached PHY 1 (IRQ -1) to driver Micrel KSZ8041RNLIto the correct:
net eth0: attached PHY 1 (IRQ 416) to driver Micrel KSZ8041RNLISigned-off-by Ben Dooks <[email protected]>--- drivers/of/of_mdio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/of/of_mdio.c +1
-1@@ -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,drivers/of/of_mdio.c static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi · line 61
Quoted 7 lines
drivers/of/of_mdio.c +0
-4@@ -55,11 +55,11 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chireturn 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;I cannot for the life for me remeber why the code was structured that way. Your change is better.
drivers/of/of_mdio.c static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi · line 63
Quoted 6 lines
drivers/of/of_mdio.c +5
-0+ rc =irq_of_parse_and_map (child,0 ); +if (rc >0 ) { + mdio->irq[addr] = rc; + phy->irq = rc; + } }The outer if is merely protecting against no irq array being allocated for the bus. Would not the following be better:
Quoted 6 lines
rc = irq_of_parse_and_map(child, 0); if (rc > 0) { phy->irq = rc; if (mdio->irq) mdio->irq[addr] = rc; }Thanks, that makes sense, although we've both failed to work out if
mdio->irqis set, and rc <= 0 case, so:Quoted 9 lines
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]; }
Quoted 3 lines
Is this actually a valid thing to do? I think the only time mdio->irq[] is non-zero is when it is set to
PHY_POLL. Is it valid to setphy->irqtoPHY_POLL? I didn't think it was.
It is valid, AFAIK.
Quoted 5 lines
g.
Quoted 3 lines
--
Ben Dooks http://www.codethink.co.uk/
Senior Engineer Codethink - Providing Genius
WBR, Sergei
Hello.
Quoted 14 lines · Florian Fainelli
Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
The
of_mdiobus_register_phy()is not settingphy->irqthis causing some drivers to incorrectly assume that the PHY does not have an IRQ associated with it or install an interrupt handler for the PHY.Simplify the code setting irq and set the
phy->irqat the same time so that the case ifmdio->irqis not NULL is easier to read.The real bug fix, which is not properly explained here, is that
irq_of_parse_and_map()should return values > 0 when the interrupt is valid, so this makes me wonder why we are not propagating the return value fromirq_of_parse_and_map()in case the call toof_irq_parse_one()does return something non-zero?
Quoted 7 lines
Quoted 3 lines
No, the first issue is
phy->devnever gets set, which causes the issue. The cleanup was added as it seemed easier to put it in with this.Ok, that really needs to be mentioned in the commit message, even being quite familiar (and possibly dumb too) with the code, I could not figure this out by reading your patch.
Yes, the main issue was that phy->irq wasn't overridden from the value set
by phy_device_create().
Quoted 7 lines
Quoted 2 lines
I think
phy->irqis already initialised toPHY_POLLand thus there is no need to setphy->irqif theirq_of_parse_and_map()fails.That is correct, the reason why I introduced 7d97637 ("net:
of_mdio:
do not overwrite PHY interrupt configuration") was that you are also allowed to change the irq type before calling intoof_mdiobus_register(),
Not really: of_mdiobus_register() init's all of mdio->irq[] with IRQ_POLL,
thus wiping out all of the previous initialization, so I don't know what you did achieve with the aforementioned commit.
Quoted 3 lines
so we want to preserve other irq values being
set here, such asPHY_IGNORE_INTERRUPT. Your patch does take care of that since it only overrides the irq in case we could parse it.
And it should have stayed that way. The latter change was unnecessary.
WBR, Sergei