net: phy: improve starting PHY
Subsystems (4)
Heiner Kallweit
maintainerv2 cover net: phy: improve starting PHY
This patch series improves few aspects of starting the PHY.
v2:
- improve a warning in patch 4
Heiner Kallweit (4):
net: phy: start state machine in phy_start only
net: phy: warn if phy_start is called from invalid state
net: phy: start interrupts in phy_start
net: phy: change phy_start_interrupts to phy_request_interrupt
drivers/net/phy/phy.c | 64 ++++++++++++++++++------------------ drivers/net/phy/phy_device.c | 5 ++- drivers/net/phy/phylink.c | 5 ++- include/linux/phy.h | 2 +- 4 files changed, 37 insertions(+), 39 deletions(-)
Signature · 1 line
2.20.1
Heiner Kallweit
maintainerPATCH v2 1/4 net: phy: start state machine in phy_start only
The state machine is a no-op before phy_start() has been called. Therefore let's enable it in phy_start() only. In phy_start() let's call phy_start_machine() instead of phy_trigger_machine(). phy_start_machine is an alias for phy_trigger_machine but it makes clearer that we start the state machine here instead of just triggering a run.
--- drivers/net/phy/phy.c | 2 +- drivers/net/phy/phy_device.c | 1 - drivers/net/phy/phylink.c | 1 - 3 files changed, 1 insertion(+), 3 deletions(-)
drivers/net/phy/phy.c +1 -1
@@ -883,7 +883,7 @@ void phy_start(struct phy_device *phydev) }mutex_unlock (&phydev->lock); -phy_trigger_machine (phydev); +phy_start_machine (phydev); }EXPORT_SYMBOL (phy_start);
drivers/net/phy/phy_device.c +0 -1
@@ -944,7 +944,6 @@ int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,return rc;phy_prepare_link (phydev, handler); -phy_start_machine (phydev);if (phydev->irq >0 )phy_start_interrupts (phydev);
drivers/net/phy/phylink.c +0 -1
@@ -679,7 +679,6 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy) __ETHTOOL_LINK_MODE_MASK_NBITS, pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS, phy->advertising); -phy_start_machine (phy);if (phy->irq >0 )phy_start_interrupts (phy);
Signature · 1 line
2.20.1
Andrew Lunn
maintainerRe: [PATCH net-next v2 1/4] net: phy: start state machine in phy_start only
Quoted 6 lines · Heiner Kallweit
The state machine is a no-op before
phy_start()has been called. Therefore let's enable it inphy_start()only. Inphy_start()let's callphy_start_machine()instead ofphy_trigger_machine().phy_start_machineis an alias forphy_trigger_machinebut it makes clearer that we start the state machine here instead of just triggering a run.
Hi Heiner
Documentation/networking/phy.txt has a section "Doing it all yourself" It would be good to review that, and make sure that documentation is still valid. I'm not sure any MAC driver actually does do it all itself. So it might be worth reviewing the whole document and making updates to remove parts of the text.
Andrew
Heiner Kallweit
maintainerRe: [PATCH net-next v2 1/4] net: phy: start state machine in phy_start only
Quoted 8 lines · Andrew Lunn
Quoted 6 lines · Heiner Kallweit
The state machine is a no-op before
phy_start()has been called. Therefore let's enable it inphy_start()only. Inphy_start()let's callphy_start_machine()instead ofphy_trigger_machine().phy_start_machineis an alias forphy_trigger_machinebut it makes clearer that we start the state machine here instead of just triggering a run.
Quoted 8 lines
Hi Heiner
Documentation/networking/phy.txthas a section "Doing it all yourself" It would be good to review that, and make sure that documentation is still valid. I'm not sure any MAC driver actually does do it all itself. So it might be worth reviewing the whole document and making updates to remove parts of the text.
Right. I figured out that I have update phy.txt anyway because I recently removed phy_stop_interrupts which is referenced in the documentation. OK if we leave the patch series as is and I submit the documentation update as a separate patch?
Quoted 3 lines
Andrew
Heiner
Andrew Lunn
maintainerRe: [PATCH net-next v2 1/4] net: phy: start state machine in phy_start only
Quoted 4 lines
Right. I figured out that I have update phy.txt anyway because I recently removed
phy_stop_interruptswhich is referenced in the documentation. OK if we leave the patch series as is and I submit the documentation update as a separate patch?
Hi Heiner
Fixing the documentation separately is O.K. It might also be a good time to convert it to rst.
Andrew
Heiner Kallweit
maintainerRe: [PATCH net-next v2 1/4] net: phy: start state machine in phy_start only
Quoted 10 lines · Andrew Lunn
Quoted 4 lines
Right. I figured out that I have update phy.txt anyway because I recently removed
phy_stop_interruptswhich is referenced in the documentation. OK if we leave the patch series as is and I submit the documentation update as a separate patch?Hi Heiner
Fixing the documentation separately is O.K. It might also be a good time to convert it to rst.
Thanks for the hint regarding rst. I converted the document and at least restview is (syntactically) happy with it. Are you aware of any checker for kernel rst documentation?
The link to the 802.3 standard is dead. On the official IEEE website the standards are available for significant money only. Not sure whether any other link to this standard is legal with regard to copyright.
Quoted 2 lines
Andrew
Heiner
Andrew Lunn
maintainerRe: [PATCH net-next v2 1/4] net: phy: start state machine in phy_start only
Quoted 6 lines · Heiner Kallweit
Quoted 5 lines · Andrew Lunn
Quoted 4 lines
Right. I figured out that I have update phy.txt anyway because I recently removed
phy_stop_interruptswhich is referenced in the documentation. OK if we leave the patch series as is and I submit the documentation update as a separate patch?
Quoted 8 lines
Quoted 5 lines
Hi Heiner
Fixing the documentation separately is O.K. It might also be a good time to convert it to rst.
Thanks for the hint regarding rst. I converted the document and at least restview is (syntactically) happy with it. Are you aware of any checker for kernel rst documentation?
Hi Heiner
Do you try make htmldocs? It might need linking into the documentation tree for that to work.
Quoted 4 lines
The link to the 802.3 standard is dead. On the official IEEE website the standards are available for significant money only. Not sure whether any other link to this standard is legal with regard to copyright.
I think it should still be available as part of IEEE GET Program. You probably cannot give a direct link to it, but maybe a link to the program could be given?
Andrew
Re: [PATCH net-next v2 1/4] net: phy: start state machine in phy_start only
In reply to Heiner KallweitQuoted 17 lines · Heiner Kallweit
Quoted 8 lines · Andrew Lunn
Quoted 6 lines · Heiner Kallweit
The state machine is a no-op before
phy_start()has been called. Therefore let's enable it inphy_start()only. Inphy_start()let's callphy_start_machine()instead ofphy_trigger_machine().phy_start_machineis an alias forphy_trigger_machinebut it makes clearer that we start the state machine here instead of just triggering a run.Quoted 8 lines
Hi Heiner
Documentation/networking/phy.txthas a section "Doing it all yourself" It would be good to review that, and make sure that documentation is still valid. I'm not sure any MAC driver actually does do it all itself. So it might be worth reviewing the whole document and making updates to remove parts of the text.
Quoted 4 lines
Right. I figured out that I have update phy.txt anyway because I recently removed
phy_stop_interruptswhich is referenced in the documentation. OK if we leave the patch series as is and I submit the documentation update as a separate patch?
I think you need to be careful here and not break what is allowed in the "Doing it all yourself" section. The amd-xgbe driver makes use of this functionality and does not use phy_start()/phy_stop(). Specifically, it does:
get_phy_device();
phy_device_register();
phy_attach_direct();
At which point it uses phy_start_aneg(), phy_read(), phy_write(), phy_read_status() and phy_aneg_done().
I'm not sure what other drivers out there that make use of this support within phylib.
Btw, I did notice this revert that was applied that eliminated a warning that I started seeing in 5.0, so that is good:
d9f903f6af3d ("net: phy: fix too strict check in phy_start_aneg")
Thanks,
Tom
Quoted 6 lines
Quoted 4 lines
Andrew
Heiner
Heiner Kallweit
maintainerRe: [PATCH net-next v2 1/4] net: phy: start state machine in phy_start only
Quoted 31 lines · Thomas
Quoted 17 lines · Heiner Kallweit
Quoted 8 lines · Andrew Lunn
Quoted 6 lines · Heiner Kallweit
The state machine is a no-op before
phy_start()has been called. Therefore let's enable it inphy_start()only. Inphy_start()let's callphy_start_machine()instead ofphy_trigger_machine().phy_start_machineis an alias forphy_trigger_machinebut it makes clearer that we start the state machine here instead of just triggering a run.Quoted 8 lines
Hi Heiner
Documentation/networking/phy.txthas a section "Doing it all yourself" It would be good to review that, and make sure that documentation is still valid. I'm not sure any MAC driver actually does do it all itself. So it might be worth reviewing the whole document and making updates to remove parts of the text.Quoted 4 lines
Right. I figured out that I have update phy.txt anyway because I recently removed
phy_stop_interruptswhich is referenced in the documentation. OK if we leave the patch series as is and I submit the documentation update as a separate patch?I think you need to be careful here and not break what is allowed in the "Doing it all yourself" section. The amd-xgbe driver makes use of this functionality and does not use phy_start()/phy_stop(). Specifically, it does:
get_phy_device();
phy_device_register();
phy_attach_direct();
Quoted 3 lines
At which point it uses
phy_start_aneg(),phy_read(),phy_write(),phy_read_status()andphy_aneg_done().
Thanks for the hint, Tom. I *think* the changes should be safe. However, if AMD has a regression test suite I'd appreciate if you could test the changes upfront or once they reach net-next.
Quoted 16 lines
I'm not sure what other drivers out there that make use of this support within phylib.
Btw, I did notice this revert that was applied that eliminated a warning that I started seeing in 5.0, so that is good:
d9f903f6af3d("net: phy: fix too strict check inphy_start_aneg")Thanks,
TomQuoted 6 lines
Quoted 4 lines
Andrew
Heiner
Re: [PATCH net-next v2 1/4] net: phy: start state machine in phy_start only
Hi Heiner
Quoted 30 lines · Heiner Kallweit
Quoted 29 lines · Thomas
Quoted 16 lines · Heiner Kallweit
Quoted 7 lines · Andrew Lunn
Quoted 6 lines · Heiner Kallweit
The state machine is a no-op before
phy_start()has been called. Therefore let's enable it inphy_start()only. Inphy_start()let's callphy_start_machine()instead ofphy_trigger_machine().phy_start_machineis an alias forphy_trigger_machinebut it makes clearer that we start the state machine here instead of just triggering a run.Quoted 8 lines
Hi Heiner
Documentation/networking/phy.txthas a section "Doing it all yourself" It would be good to review that, and make sure that documentation is still valid. I'm not sure any MAC driver actually does do it all itself. So it might be worth reviewing the whole document and making updates to remove parts of the text.Quoted 4 lines
Right. I figured out that I have update phy.txt anyway because I recently removed
phy_stop_interruptswhich is referenced in the documentation. OK if we leave the patch series as is and I submit the documentation update as a separate patch?I think you need to be careful here and not break what is allowed in the "Doing it all yourself" section. The amd-xgbe driver makes use of this functionality and does not use phy_start()/phy_stop(). Specifically, it does:
get_phy_device();
phy_device_register();
phy_attach_direct();
Quoted 7 lines
Quoted 3 lines
At which point it uses
phy_start_aneg(),phy_read(),phy_write(),phy_read_status()andphy_aneg_done().Thanks for the hint, Tom. I *think* the changes should be safe. However, if AMD has a regression test suite I'd appreciate if you could test the changes upfront or once they reach net-next.
Can you please cc: on your changes so you I can verify them before they get pushed upstream?
Heiner Kallweit
maintainerPATCH v2 2/4 net: phy: warn if phy_start is called from invalid state
In reply to Heiner Kallweitphy_start() should be called from states PHY_READY or PHY_HALTED only. Check for this to detect misbehaving drivers. Also the state machine should be started only when being called from one of the valid states.
--- drivers/net/phy/phy.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/phy/phy.c +9 -2
@@ -861,9 +861,16 @@ void phy_start(struct phy_device *phydev)mutex_lock (&phydev->lock); +if (phydev->state !=PHY_READY && phydev->state !=PHY_HALTED ) { +WARN (1 ,"called from state %s\n" , +phy_state_to_str (phydev->state)); + goto out; + } +switch (phydev->state) {case PHY_READY : phydev->state =PHY_UP ; +phy_start_machine (phydev);break ;case PHY_HALTED :/* if phy was suspended, bring the physical link up again */
@@ -877,13 +884,13 @@ void phy_start(struct phy_device *phydev) } phydev->state =PHY_RESUMING ; +phy_start_machine (phydev);break ;default :break ; } +out:mutex_unlock (&phydev->lock); - -phy_start_machine (phydev); }EXPORT_SYMBOL (phy_start);
Signature · 1 line
2.20.1
Andrew Lunn
maintainerRe: [PATCH net-next v2 2/4] net: phy: warn if phy_start is called from invalid state
Quoted 14 lines · Heiner Kallweit
phy_start()should be called from statesPHY_READYorPHY_HALTEDonly. Check for this to detect misbehaving drivers. Also the state machine should be started only when being called from one of the valid states.Signed-off-by Heiner Kallweit <[email protected]>--- drivers/net/phy/phy.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/net/phy/phy.c +0
-0
drivers/net/phy/phy.c void phy_start(struct phy_device *phydev) · line 868
Quoted 8 lines
drivers/net/phy/phy.c +5
-0@@ -861,9 +861,16 @@ void phy_start(struct phy_device *phydev)mutex_lock (&phydev->lock); +if (phydev->state !=PHY_READY && phydev->state !=PHY_HALTED ) { +WARN (1 ,"called from state %s\n" , +phy_state_to_str (phydev->state)); + goto out; + }
Hi Heiner
Warning is good. But jumping to out i'm not so sure about. Drivers which are 'broken' work well enough that users don't know they are broken. But jumping to out is going to really break them. It seems better to have the kernel only warn for one cycle so we find out about such drivers and fix them, and later add the goto out.
Andrew
Heiner Kallweit
maintainerRe: [PATCH net-next v2 2/4] net: phy: warn if phy_start is called from invalid state
Quoted 26 lines · Andrew Lunn
Quoted 14 lines · Heiner Kallweit
phy_start()should be called from statesPHY_READYorPHY_HALTEDonly. Check for this to detect misbehaving drivers. Also the state machine should be started only when being called from one of the valid states.Signed-off-by Heiner Kallweit <[email protected]>--- drivers/net/phy/phy.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/net/phy/phy.c +0
-0drivers/net/phy/phy.c void phy_start(struct phy_device *phydev) · line 868
Quoted 8 lines
drivers/net/phy/phy.c +5
-0@@ -861,9 +861,16 @@ void phy_start(struct phy_device *phydev)mutex_lock (&phydev->lock); +if (phydev->state !=PHY_READY && phydev->state !=PHY_HALTED ) { +WARN (1 ,"called from state %s\n" , +phy_state_to_str (phydev->state)); + goto out; + }Hi Heiner
Quoted 6 lines
Warning is good. But jumping to out i'm not so sure about. Drivers which are 'broken' work well enough that users don't know they are broken. But jumping to out is going to really break them. It seems better to have the kernel only warn for one cycle so we find out about such drivers and fix them, and later add the goto out.
For all invalid states phy_start() basically was a no-op. All it did was triggering a state machine run, but for all "running" states the poll loop was active anyway. And if called from PHY_DOWN, the state machine does nothing. Therefore I see no scenario where jumping to out would break anything.
Quoted 2 lines
Andrew
Heiner
Andrew Lunn
maintainerRe: [PATCH net-next v2 2/4] net: phy: warn if phy_start is called from invalid state
Quoted 5 lines
For all invalid states
phy_start()basically was a no-op. All it did was triggering a state machine run, but for all "running" states the poll loop was active anyway. And if called fromPHY_DOWN, the state machine does nothing. Therefore I see no scenario where jumping to out would break anything.
Hi Heiner
It is useful to put this sort of analysis in the commit message. You then won't get people like me asking about it.
Andrew
Heiner Kallweit
maintainerRe: [PATCH net-next v2 2/4] net: phy: warn if phy_start is called from invalid state
Quoted 11 lines · Andrew Lunn
Quoted 5 lines
For all invalid states
phy_start()basically was a no-op. All it did was triggering a state machine run, but for all "running" states the poll loop was active anyway. And if called fromPHY_DOWN, the state machine does nothing. Therefore I see no scenario where jumping to out would break anything.Hi Heiner
It is useful to put this sort of analysis in the commit message. You then won't get people like me asking about it.
Will add this to my "best practices" list ;)
Quoted 2 lines
Andrew
Heiner
Heiner Kallweit
maintainerPATCH v2 3/4 net: phy: start interrupts in phy_start
In reply to Heiner KallweitInterrupts don't have to be enabled before calling phy_start(). Therefore let's enable them in phy_start(). In a subsequent step we'll remove enabling interrupts from phy_connect_direct().
--- drivers/net/phy/phy.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-)
drivers/net/phy/phy.c +14 -20
@@ -857,7 +857,7 @@ EXPORT_SYMBOL(phy_stop);*/ void phy_start (struct phy_device *phydev) { -int err =0 ; +int err;mutex_lock (&phydev->lock);
@@ -867,28 +867,22 @@ void phy_start(struct phy_device *phydev) goto out; } -switch (phydev->state) { -case PHY_READY : - phydev->state =PHY_UP ; -phy_start_machine (phydev); -break ; -case PHY_HALTED : -/* if phy was suspended, bring the physical link up again */ -__phy_resume (phydev); +/* if phy was suspended, bring the physical link up again */ +__phy_resume (phydev); -/* make sure interrupts are re-enabled for the PHY */ -if (phy_interrupt_is_valid (phydev)) { - err =phy_enable_interrupts (phydev); -if (err <0 ) -break ; - } +/* make sure interrupts are enabled for the PHY */ +if (phy_interrupt_is_valid (phydev)) { + err =phy_enable_interrupts (phydev); +if (err <0 ) + goto out; + } +if (phydev->state ==PHY_READY ) + phydev->state =PHY_UP ; +else phydev->state =PHY_RESUMING ; -phy_start_machine (phydev); -break ; -default : -break ; - } + +phy_start_machine (phydev); out:mutex_unlock (&phydev->lock); }
Signature · 1 line
2.20.1
Heiner Kallweit
maintainerPATCH v2 4/4 net: phy: change phy_start_interrupts to phy_request_interrupt
In reply to Heiner KallweitNow that we enable the interrupts in phy_start() we don't have to do it before. Therefore remove enabling interrupts from phy_start_interrupts() and rename this function to reflect the changed functionality.
v2:
- improve warning to clearly state that we fall back to polling
--- drivers/net/phy/phy.c | 23 +++++++++++------------ drivers/net/phy/phy_device.c | 4 ++-- drivers/net/phy/phylink.c | 4 ++-- include/linux/phy.h | 2 +- 4 files changed, 16 insertions(+), 17 deletions(-)
drivers/net/phy/phy.c +11 -12
@@ -790,28 +790,27 @@ static int phy_enable_interrupts(struct phy_device *phydev) }/** -* phy_start_interrupts - request and enable interrupts for a PHY device +* phy_request_interrupt - request interrupt for a PHY device * @phydev: target phy_device struct * * Description: Request the interrupt for the given PHY. * If this fails, then we set irq to PHY_POLL. -* Otherwise, we enable the interrupts in the PHY. * This should only be called with a valid IRQ number. -* Returns 0 on success or < 0 on error. */ -int phy_start_interrupts (struct phy_device *phydev) +void phy_request_interrupt (struct phy_device *phydev) { -if (request_threaded_irq (phydev->irq,NULL , phy_interrupt, -IRQF_ONESHOT |IRQF_SHARED , -phydev_name (phydev), phydev) <0 ) { -phydev_warn (phydev,"Can't get IRQ %d\n" , phydev->irq); +int err; + + err =request_threaded_irq (phydev->irq,NULL , phy_interrupt, +IRQF_ONESHOT |IRQF_SHARED , +phydev_name (phydev), phydev); +if (err) { +phydev_warn (phydev,"Error %d requesting IRQ %d, falling back to polling\n" , + err, phydev->irq); phydev->irq =PHY_POLL ; -return 0 ; } - -return phy_enable_interrupts (phydev); } -EXPORT_SYMBOL (phy_start_interrupts); +EXPORT_SYMBOL (phy_request_interrupt);/** * phy_stop - Bring down the PHY link, and stop checking the status
drivers/net/phy/phy_device.c +2 -2
@@ -944,8 +944,8 @@ int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,return rc;phy_prepare_link (phydev, handler); -if (phydev->irq >0 ) -phy_start_interrupts (phydev); +if (phy_interrupt_is_valid (phydev)) +phy_request_interrupt (phydev);return 0 ; }
drivers/net/phy/phylink.c +2 -2
@@ -679,8 +679,8 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy) __ETHTOOL_LINK_MODE_MASK_NBITS, pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS, phy->advertising); -if (phy->irq >0 ) -phy_start_interrupts (phy); +if (phy_interrupt_is_valid (phy)) +phy_request_interrupt (phy);return 0 ; }
include/linux/phy.h +1 -1
@@ -1045,7 +1045,7 @@ void phy_ethtool_ksettings_get(struct phy_device *phydev,int phy_ethtool_ksettings_set (struct phy_device *phydev,const struct ethtool_link_ksettings *cmd);int phy_mii_ioctl (struct phy_device *phydev,struct ifreq *ifr,int cmd); -int phy_start_interrupts (struct phy_device *phydev); +void phy_request_interrupt (struct phy_device *phydev);void phy_print_status (struct phy_device *phydev);int phy_set_max_speed (struct phy_device *phydev,u32 max_speed);void phy_remove_link_mode (struct phy_device *phydev,u32 link_mode);
Signature · 1 line
2.20.1
David Miller
maintainerFrom: Heiner Kallweit <[email protected]>
Date: Sun, 20 Jan 2019 09:59:46 +0100
Quoted 4 lines
This patch series improves few aspects of starting the PHY.
v2:
- improve a warning in patch 4
Please update the commit message as per Andrew's feedback for patch #2.
You might as well do this while we wait for the AMD testing.
Thanks!