All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Gerhard Engleder <gerhard@engleder-embedded.com>
Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	netdev@vger.kernel.org
Subject: Re: [PATCH net-next v6 2/7] net: phy: Support speed selection for PHY loopback
Date: Wed, 12 Feb 2025 02:48:42 +0100	[thread overview]
Message-ID: <57e02f9b-ff5e-44fa-b2fa-cbd7dd93408a@lunn.ch> (raw)
In-Reply-To: <20250209190827.29128-3-gerhard@engleder-embedded.com>

> +int phy_loopback(struct phy_device *phydev, bool enable, int speed)
> +{
> +	bool link_up = false;
> +	int ret = 0;
> +
> +	if (!phydev->drv)
> +		return -EIO;
> +
> +	mutex_lock(&phydev->lock);
> +
> +	if (enable && phydev->loopback_enabled) {
> +		ret = -EBUSY;
> +		goto out;
> +	}
> +
> +	if (!enable && !phydev->loopback_enabled) {
> +		ret = -EINVAL;
> +		goto out;
> +	}
> +
> +	if (enable) {
> +		/*
> +		 * Link up is signaled with a defined speed. If speed changes,
> +		 * then first link down and after that link up needs to be
> +		 * signaled.
> +		 */
> +		if (phydev->link && phydev->state == PHY_RUNNING) {
> +			/* link is up and signaled */
> +			if (speed && phydev->speed != speed) {
> +				/* signal link down and up for new speed */
> +				phydev->link = false;
> +				phydev->state = PHY_NOLINK;
> +				phy_link_down(phydev);

If you set the link down here...

> +
> +				link_up = true;
> +			}
> +		} else {
> +			/* link is not signaled */
> +			if (speed) {
> +				/* signal link up for new speed */
> +				link_up = true;
> +			}
> +		}
> +	}
> +
> +	if (phydev->drv->set_loopback)
> +		ret = phydev->drv->set_loopback(phydev, enable, speed);
> +	else
> +		ret = genphy_loopback(phydev, enable, speed);
> +
> +	if (ret)
> +		goto out;

and this fails, you leave the link down. You should make an attempt to
restore the link to the old state before returning the error.

	Andrew

  reply	other threads:[~2025-02-12  1:49 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-09 19:08 [PATCH net-next v6 0/7] Support loopback mode speed selection Gerhard Engleder
2025-02-09 19:08 ` [PATCH net-next v6 1/7] net: phy: Allow loopback speed selection for PHY drivers Gerhard Engleder
2025-02-12  1:53   ` Andrew Lunn
2025-02-09 19:08 ` [PATCH net-next v6 2/7] net: phy: Support speed selection for PHY loopback Gerhard Engleder
2025-02-12  1:48   ` Andrew Lunn [this message]
2025-02-12 20:01     ` Gerhard Engleder
2025-02-09 19:08 ` [PATCH net-next v6 3/7] net: phy: micrel: Add loopback support Gerhard Engleder
2025-02-12  1:51   ` Andrew Lunn
2025-02-12 20:03     ` Gerhard Engleder
2025-02-09 19:08 ` [PATCH net-next v6 4/7] net: phy: marvell: Align set_loopback() implementation Gerhard Engleder
2025-02-12  1:53   ` Andrew Lunn
2025-02-09 19:08 ` [PATCH net-next v6 5/7] tsnep: Select speed for loopback Gerhard Engleder
2025-02-12  1:55   ` Andrew Lunn
2025-02-09 19:08 ` [PATCH net-next v6 6/7] net: selftests: Export net_test_phy_loopback_* Gerhard Engleder
2025-02-12  2:23   ` Andrew Lunn
2025-02-12 20:13     ` Gerhard Engleder
2025-02-12 20:46       ` Andrew Lunn
2025-02-12 21:36         ` Gerhard Engleder
2025-02-12 22:34           ` Andrew Lunn
2025-02-12 22:53             ` Russell King (Oracle)
2025-02-09 19:08 ` [PATCH net-next v6 7/7] tsnep: Add PHY loopback selftests Gerhard Engleder

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=57e02f9b-ff5e-44fa-b2fa-cbd7dd93408a@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gerhard@engleder-embedded.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.