netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Anssi Hannula <anssi.hannula@bitwise.fi>,
	Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>, netdev@vger.kernel.org
Subject: Re: [PATCH 2/2] net: phy: ensure autoneg is configured when resuming a phydev
Date: Fri, 30 Nov 2018 23:16:32 +0100	[thread overview]
Message-ID: <5eb118f2-a355-2488-d503-bf64a9b7c801@gmail.com> (raw)
In-Reply-To: <20181130184546.28384-3-anssi.hannula@bitwise.fi>

On 30.11.2018 19:45, Anssi Hannula wrote:
> When a PHY_HALTED phydev is resumed by phy_start(), it is set to
> PHY_RESUMING to wait for the link to come up.
> 
> However, if the phydev was put to PHY_HALTED (by e.g. phy_stop()) before
> autonegotiation was ever started by phy_state_machine(), autonegotiation
> remains unconfigured, i.e. phy_config_aneg() is never called.
> 
phy_stop() should only be called once the PHY was started. But it's
right that we don't have full control over it because misbehaving
drivers may call phy_stop() even if the PHY hasn't been started yet.

I think phy_error() and phy_stop() should be extended to set the state
to PHY_HALTED only if the PHY is in a started state, means:
don't touch the state if it's DOWN, READY, or HALTED.
In case of phy_error() it's more a precaution, because it's used within
phylib only and AFAICS it can be triggered from a started state only.

So yes, there is a theoretical issue. But as you wrote already, I think
there's a better way to deal with it.

For checking whether PHY is in a started state you could use the helper
which is being discussed here:
https://marc.info/?l=linux-netdev&m=154360368104946&w=2


> Fix that by going to PHY_UP instead of PHY_RESUMING if autonegotiation
> has never been configured.
> 
> Signed-off-by: Anssi Hannula <anssi.hannula@bitwise.fi>
> ---
> 
> This doesn't feel as clean is I'd like to, though. Maybe there is a
> better way?
> 
> 
>  drivers/net/phy/phy.c | 11 ++++++++++-
>  include/linux/phy.h   |  2 ++
>  2 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index d46858694db9..7a650cce7599 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -553,6 +553,8 @@ int phy_start_aneg(struct phy_device *phydev)
>  	if (err < 0)
>  		goto out_unlock;
>  
> +	phydev->autoneg_configured = 1;
> +
>  	if (phydev->state != PHY_HALTED) {
>  		if (AUTONEG_ENABLE == phydev->autoneg) {
>  			err = phy_check_link_status(phydev);
> @@ -893,7 +895,14 @@ void phy_start(struct phy_device *phydev)
>  				break;
>  		}
>  
> -		phydev->state = PHY_RESUMING;
> +		/* if autoneg/forcing was never configured, go back to PHY_UP
> +		 * to make that happen
> +		 */
> +		if (!phydev->autoneg_configured)
> +			phydev->state = PHY_UP;
> +		else
> +			phydev->state = PHY_RESUMING;
> +
>  		break;
>  	default:
>  		break;
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 8f927246acdb..b306d5ed9d09 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -389,6 +389,8 @@ struct phy_device {
>  	unsigned loopback_enabled:1;
>  
>  	unsigned autoneg:1;
> +	/* autoneg has been configured at least once */
> +	unsigned autoneg_configured:1;
>  	/* The most recently read link state */
>  	unsigned link:1;
>  
> 

  reply	other threads:[~2018-12-01  9:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-30 18:45 [PATCH 0/2] net: phy: fixes to PHY_HALTED handling Anssi Hannula
2018-11-30 18:45 ` [PATCH 1/2] net: phy: suspend phydev on PHY_HALTED even if there is no link Anssi Hannula
2018-11-30 18:45 ` [PATCH 2/2] net: phy: ensure autoneg is configured when resuming a phydev Anssi Hannula
2018-11-30 22:16   ` Heiner Kallweit [this message]
2018-12-03 10:43     ` Anssi Hannula
2018-12-03 21:41       ` Heiner Kallweit
2018-12-04 12:58         ` Anssi Hannula

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5eb118f2-a355-2488-d503-bf64a9b7c801@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=anssi.hannula@bitwise.fi \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).