From: Andrew Lunn <andrew@lunn.ch>
To: Vivian Wang <wangruikang@iscas.ac.cn>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Yixun Lan <dlan@gentoo.org>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
Vadim Fedorenko <vadim.fedorenko@linux.dev>,
Troy Mitchell <troy.mitchell@linux.spacemit.com>,
netdev@vger.kernel.org, linux-riscv@lists.infradead.org,
spacemit@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] net: spacemit: Implement emac_set_pauseparam properly
Date: Thu, 30 Oct 2025 22:32:24 +0100 [thread overview]
Message-ID: <2eb5f9fc-d173-4b9e-89a3-87ad17ddd163@lunn.ch> (raw)
In-Reply-To: <20251030-k1-ethernet-fix-autoneg-v1-1-baa572607ccc@iscas.ac.cn>
On Thu, Oct 30, 2025 at 10:31:44PM +0800, Vivian Wang wrote:
> emac_set_pauseparam (the set_pauseparam callback) didn't properly update
> phydev->advertising. Fix it by changing it to call phy_set_asym_pause.
This patch is doing a lot more than that.
Please break this patch up into smaller parts.
One obvious part you can break out is emac_get_pauseparam() reading
from hardware rather that state variables.
> static int emac_set_pauseparam(struct net_device *dev,
> struct ethtool_pauseparam *pause)
> {
> struct emac_priv *priv = netdev_priv(dev);
> - u8 fc = 0;
> + struct phy_device *phydev = dev->phydev;
>
> - priv->flow_control_autoneg = pause->autoneg;
> + if (!phydev)
> + return -ENODEV;
I'm not sure that is the correct condition. emac_up() will fail if it
cannot find the PHY. What you need to be testing here is if the
interface is admin down, and so is not connected to the PHY. If so,
-ENETDOWN would be more appropriate.
> - if (pause->autoneg) {
> - emac_set_fc_autoneg(priv);
> - } else {
> - if (pause->tx_pause)
> - fc |= FLOW_CTRL_TX;
> + if (!phy_validate_pause(phydev, pause))
> + return -EINVAL;
>
> - if (pause->rx_pause)
> - fc |= FLOW_CTRL_RX;
> + priv->flow_control_autoneg = pause->autoneg;
>
> - emac_set_fc(priv, fc);
> - }
> + phy_set_asym_pause(dev->phydev, pause->rx_pause, pause->tx_pause);
It is hard to read what this patch is doing, but there are 3 use cases.
1) general autoneg for link speed etc, and pause autoneg
2) general autoneg for link speed etc, and forced pause
3) forced link speed etc, and forced pause.
I don't see all these being handled. It gets much easier to get this
right if you make use of phylink, since phylink handles all the
business logic for you.
Andrew
next prev parent reply other threads:[~2025-10-30 21:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-30 14:31 Vivian Wang
2025-10-30 20:30 ` Michael Opdenacker
2025-10-30 21:32 ` Andrew Lunn [this message]
2025-10-31 7:22 ` Vivian Wang
2025-10-31 12:43 ` Andrew Lunn
2025-10-31 13:29 ` Vivian Wang
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=2eb5f9fc-d173-4b9e-89a3-87ad17ddd163@lunn.ch \
--to=andrew@lunn.ch \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=dlan@gentoo.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=spacemit@lists.linux.dev \
--cc=troy.mitchell@linux.spacemit.com \
--cc=vadim.fedorenko@linux.dev \
--cc=wangruikang@iscas.ac.cn \
/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
all inboxes | Powered by JetHome®