From: Javen <javen_xu@realsil.com.cn>
To: Andrew Lunn <andrew@lunn.ch>
Cc: "hkallweit1@gmail.com" <hkallweit1@gmail.com>,
"nic_swsd@realtek.com" <nic_swsd@realtek.com>,
"andrew+netdev@lunn.ch" <andrew+netdev@lunn.ch>,
"davem@davemloft.net" <davem@davemloft.net>,
"edumazet@google.com" <edumazet@google.com>,
"kuba@kernel.org" <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"maxime.chevallier@bootlin.com" <maxime.chevallier@bootlin.com>,
"horms@kernel.org" <horms@kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"daniel@makrotopia.org" <daniel@makrotopia.org>,
"linux@armlinux.org.uk" <linux@armlinux.org.uk>,
"enelsonmoore@gmail.com" <enelsonmoore@gmail.com>,
"daniel@thingy.jp" <daniel@thingy.jp>
Subject: RE: [PATCH net-next v7 2/7] net: phy: phylink: add helper to modify pause
Date: Thu, 23 Jul 2026 02:50:46 +0000 [thread overview]
Message-ID: <65141a327af44b938ba2fb94e3344da3@realsil.com.cn> (raw)
In-Reply-To: <8a90be50-8a45-4a27-a0a7-adfd1156c30e@lunn.ch>
>
>> +/**
>> + * phylink_update_mac_pause_capabilities() - Dynamically update MAC
>> +pause
>> + * @pl: a pointer to a &struct phylink returned from phylink_create()
>> + * @mac_pause: the new MAC pause capabilities mask
>> + *
>> + * This function allows a MAC driver to dynamically change its pause
>> +state,
>> + * such as losing/gaining Pause frame support based on MTU size.
>> + * It recalculates supported link modes and triggers renegotiation if needed.
>> + */
>> +void phylink_update_mac_pause_capabilities(struct phylink *pl,
>> +unsigned long mac_pause) {
>> + struct phylink_link_state *config = &pl->link_config;
>> + unsigned long old_pause;
>> + int pause_state;
>> +
>> + ASSERT_RTNL();
>> +
>> + if (mac_pause & ~(MAC_SYM_PAUSE | MAC_ASYM_PAUSE)) {
>> + phylink_err(pl, "Attempted to dynamically change non-pause MAC
>capabilities\n");
>> + return;
>> + }
>> +
>> + old_pause = pl->config->mac_capabilities & (MAC_SYM_PAUSE |
>MAC_ASYM_PAUSE);
>> + if (old_pause == mac_pause)
>> + return;
>> +
>> + mutex_lock(&pl->state_mutex);
>> +
>> + pl->config->mac_capabilities &= ~(MAC_SYM_PAUSE |
>MAC_ASYM_PAUSE);
>> + pl->config->mac_capabilities |= mac_pause;
>> +
>> + phylink_set(pl->supported, Pause);
>> + phylink_set(pl->supported, Asym_Pause);
>
>I don't know the phylink code very well. Could you explain why these are
>unconditional? It is not obvious to me.
Thanks for review.
The unconditional phylink_set() is required precisely because of how phylink_validate() works. It acts as a necessary "reset" to prevent the permanent loss of capabilities in pl->supported across MTU changes.
Consider the following scenario when MTU changes:
1. MTU 1500 -> 9000: The MAC loses Pause support. mac_pause becomes 0. When phylink_validate() is called, it correctly clears the Pause and Asym_Pause bits in pl->supported. This happens in the function call trace phylink_validate()=>phylink_validate_mac_and_pcs()=>phylink_validate_mask_caps()=>linkmode_and(supported, supported, mask), where mask represent the capability.
2. MTU 9000 -> 1500: The MAC regains Pause support. We update mac_pause back to 1. But if we simply call phylink_validate() at this point without unconditionally setting the bits first, it will take the current pl->supported (where Pause is 0 from step 1) as its input. The Pause capability will be permanently masked out and never restored.
By unconditionally setting them here, we restore the baseline to 1, allowing phylink_validate() to correctly decide whether to keep them or clear them based on the current PHY/MAC capabilities.
>
>> + if (pl->phydev)
>> + linkmode_and(pl->supported, pl->supported, pl->phydev-
>>supported);
>> + else if (pl->sfp_bus)
>> + linkmode_and(pl->supported, pl->supported,
>> + pl->sfp_support);
>
>These lines are masking out pause if the PHY or SFP does out support pause.
>But where is pause masked out if the MAC does not support pause? That is
>what i'm missing here.
If the MAC does not support pause (e.g., mac_pause == 0), those unconditionally set bits are correctly masked out during the phylink_validate() execution chain. Inside phylink_validate_mask_caps(), the mac_capabilities are converted into an ethtool linkmode mask, and the actual filtering happens via linkmode_and(state->advertising, state->advertising, mask). And mac_capabilities is from pl->config->mac_capabilities, which we set at the beginning of this patch.
BRs,
Javen
>
> Andrew
next prev parent reply other threads:[~2026-07-23 2:52 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 2:28 [PATCH net-next v7 0/7] r8169: add support for phylink javen
2026-07-22 2:29 ` [PATCH net-next v7 1/7] r8169: add speed in private struct javen
2026-07-22 2:29 ` [PATCH net-next v7 2/7] net: phy: phylink: add helper to modify pause javen
2026-07-23 0:57 ` Andrew Lunn
2026-07-23 2:50 ` Javen [this message]
2026-07-23 12:47 ` Andrew Lunn
2026-07-22 2:29 ` [PATCH net-next v7 3/7] r8169: add support for phylink javen
2026-07-23 1:04 ` Andrew Lunn
2026-07-23 3:05 ` Javen
2026-07-22 2:29 ` [PATCH net-next v7 4/7] r8169: add support for RTL8116af javen
2026-07-23 1:13 ` Andrew Lunn
2026-07-23 3:21 ` Javen
2026-07-23 12:54 ` Andrew Lunn
2026-07-24 1:44 ` Javen
2026-07-28 6:18 ` Javen
2026-07-22 2:29 ` [PATCH net-next v7 5/7] r8169: add support for RTL8127atf javen
2026-07-22 2:29 ` [PATCH net-next v7 6/7] r8169: add ltr support for RTL8117 series javen
2026-07-22 2:29 ` [PATCH net-next v7 7/7] r8169: fix RTL8116af can not enter s0idle and c10 javen
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=65141a327af44b938ba2fb94e3344da3@realsil.com.cn \
--to=javen_xu@realsil.com.cn \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=daniel@makrotopia.org \
--cc=daniel@thingy.jp \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=enelsonmoore@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=nic_swsd@realtek.com \
--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 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®