From: "Russell King (Oracle)" <rmk+kernel@armlinux•org.uk>
To: Andrew Lunn <andrew@lunn•ch>, Heiner Kallweit <hkallweit1@gmail•com>
Cc: "Broadcom internal kernel review list"
<bcm-kernel-feedback-list@broadcom•com>,
"David S. Miller" <davem@davemloft•net>,
"Eric Dumazet" <edumazet@google•com>,
"Florian Fainelli" <florian.fainelli@broadcom•com>,
"Jakub Kicinski" <kuba@kernel•org>,
"Marek Behún" <kabel@kernel•org>,
netdev@vger•kernel.org, "Paolo Abeni" <pabeni@redhat•com>
Subject: [PATCH net-next 10/10] net: phylink: use the PHY's possible_interfaces if populated
Date: Fri, 24 Nov 2023 12:28:39 +0000 [thread overview]
Message-ID: <E1r6VIV-00DDMF-Pi@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <ZWCWn+uNkVLPaQhn@shell.armlinux.org.uk>
Some PHYs such as Aquantia, Broadcom 84881, and Marvell 88X33x0 can
switch between a set of interface types depending on the negotiated
media speed, or can use rate adaption for some or all of these
interface types.
We currently assume that these are Clause 45 PHYs that are configured
not to use a specific set of interface modes, which has worked so far,
but is just a work-around. In this workaround, we validate using all
interfaces that the MAC supports, which can lead to extra modes being
advertised that can not be supported.
To properly address this, switch to using the newly introduced PHY
possible_interfaces bitmap which indicates which interface modes will
be used by the PHY as configured. We calculate the union of the PHY's
possible interfaces and MACs supported interfaces, checking that is
non-empty. If the PHY is on a SFP, we further reduce the set by those
which can be used on a SFP module, again checking that is non-empty.
Finally, we validate the subset of interfaces, taking account of
whether rate matching will be used for each individual interface mode.
This becomes independent of whether the PHY is clause 22 or clause 45.
It is encouraged that all PHYs that switch interface modes or use
rate matching should populate phydev->possible_interfaces.
Tested-by: Luo Jie <quic_luoj@quicinc•com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux•org.uk>
---
drivers/net/phy/phylink.c | 67 +++++++++++++++++++++++++++++++--------
1 file changed, 54 insertions(+), 13 deletions(-)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 39d85e47422e..48d3bd3e9fc7 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -121,6 +121,19 @@ do { \
})
#endif
+static const phy_interface_t phylink_sfp_interface_preference[] = {
+ PHY_INTERFACE_MODE_25GBASER,
+ PHY_INTERFACE_MODE_USXGMII,
+ PHY_INTERFACE_MODE_10GBASER,
+ PHY_INTERFACE_MODE_5GBASER,
+ PHY_INTERFACE_MODE_2500BASEX,
+ PHY_INTERFACE_MODE_SGMII,
+ PHY_INTERFACE_MODE_1000BASEX,
+ PHY_INTERFACE_MODE_100BASEX,
+};
+
+static DECLARE_PHY_INTERFACE_MASK(phylink_sfp_interfaces);
+
/**
* phylink_set_port_modes() - set the port type modes in the ethtool mask
* @mask: ethtool link mode mask
@@ -1764,6 +1777,47 @@ static int phylink_validate_phy(struct phylink *pl, struct phy_device *phy,
unsigned long *supported,
struct phylink_link_state *state)
{
+ DECLARE_PHY_INTERFACE_MASK(interfaces);
+
+ /* If the PHY provides a bitmap of the interfaces it will be using
+ * depending on the negotiated media speeds, use this to validate
+ * which ethtool link modes can be used.
+ */
+ if (!phy_interface_empty(phy->possible_interfaces)) {
+ /* We only care about the union of the PHY's interfaces and
+ * those which the host supports.
+ */
+ phy_interface_and(interfaces, phy->possible_interfaces,
+ pl->config->supported_interfaces);
+
+ if (phy_interface_empty(interfaces)) {
+ phylink_err(pl, "PHY has no common interfaces\n");
+ return -EINVAL;
+ }
+
+ if (phy_on_sfp(phy)) {
+ /* If the PHY is on a SFP, limit the interfaces to
+ * those that can be used with a SFP module.
+ */
+ phy_interface_and(interfaces, interfaces,
+ phylink_sfp_interfaces);
+
+ if (phy_interface_empty(interfaces)) {
+ phylink_err(pl, "SFP PHY's possible interfaces becomes empty\n");
+ return -EINVAL;
+ }
+ }
+
+ phylink_dbg(pl, "PHY %s uses interfaces %*pbl, validating %*pbl\n",
+ phydev_name(phy),
+ (int)PHY_INTERFACE_MODE_MAX,
+ phy->possible_interfaces,
+ (int)PHY_INTERFACE_MODE_MAX, interfaces);
+
+ return phylink_validate_mask(pl, phy, supported, state,
+ interfaces);
+ }
+
/* Check whether we would use rate matching for the proposed interface
* mode.
*/
@@ -3032,19 +3086,6 @@ static void phylink_sfp_detach(void *upstream, struct sfp_bus *bus)
pl->netdev->sfp_bus = NULL;
}
-static const phy_interface_t phylink_sfp_interface_preference[] = {
- PHY_INTERFACE_MODE_25GBASER,
- PHY_INTERFACE_MODE_USXGMII,
- PHY_INTERFACE_MODE_10GBASER,
- PHY_INTERFACE_MODE_5GBASER,
- PHY_INTERFACE_MODE_2500BASEX,
- PHY_INTERFACE_MODE_SGMII,
- PHY_INTERFACE_MODE_1000BASEX,
- PHY_INTERFACE_MODE_100BASEX,
-};
-
-static DECLARE_PHY_INTERFACE_MASK(phylink_sfp_interfaces);
-
static phy_interface_t phylink_choose_sfp_interface(struct phylink *pl,
const unsigned long *intf)
{
--
2.30.2
next prev parent reply other threads:[~2023-11-24 12:28 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-24 12:27 [PATCH net-next 00/10] net: phylink: improve PHY validation Russell King (Oracle)
2023-11-24 12:27 ` [PATCH net-next 01/10] net: phy: add possible interfaces Russell King (Oracle)
2023-11-25 17:06 ` Andrew Lunn
2023-11-24 12:27 ` [PATCH net-next 02/10] net: phy: marvell10g: table driven mactype decode Russell King (Oracle)
2023-11-24 12:28 ` [PATCH net-next 03/10] net: phy: marvell10g: fill in possible_interfaces Russell King (Oracle)
2023-11-25 17:09 ` Andrew Lunn
2023-11-24 12:28 ` [PATCH net-next 04/10] net: phy: bcm84881: " Russell King (Oracle)
2023-11-25 17:10 ` Andrew Lunn
2023-11-24 12:28 ` [PATCH net-next 05/10] net: phy: aquantia: fill in possible_interfaces for AQR113C Russell King (Oracle)
2023-11-25 17:11 ` Andrew Lunn
2023-11-24 12:28 ` [PATCH net-next 06/10] net: phylink: split out per-interface validation Russell King (Oracle)
2023-11-25 17:12 ` Andrew Lunn
2023-11-24 12:28 ` [PATCH net-next 07/10] net: phylink: pass PHY into phylink_validate_one() Russell King (Oracle)
2023-11-25 17:13 ` Andrew Lunn
2023-11-24 12:28 ` [PATCH net-next 08/10] net: phylink: pass PHY into phylink_validate_mask() Russell King (Oracle)
2023-11-25 17:13 ` Andrew Lunn
2023-11-24 12:28 ` [PATCH net-next 09/10] net: phylink: split out PHY validation from phylink_bringup_phy() Russell King (Oracle)
2023-11-25 17:15 ` Andrew Lunn
2023-11-24 12:28 ` Russell King (Oracle) [this message]
2023-11-25 17:18 ` [PATCH net-next 10/10] net: phylink: use the PHY's possible_interfaces if populated Andrew Lunn
2023-11-28 2:08 ` [PATCH net-next 00/10] net: phylink: improve PHY validation Jakub Kicinski
2023-11-28 2:20 ` patchwork-bot+netdevbpf
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=E1r6VIV-00DDMF-Pi@rmk-PC.armlinux.org.uk \
--to=rmk+kernel@armlinux$(echo .)org.uk \
--cc=andrew@lunn$(echo .)ch \
--cc=bcm-kernel-feedback-list@broadcom$(echo .)com \
--cc=davem@davemloft$(echo .)net \
--cc=edumazet@google$(echo .)com \
--cc=florian.fainelli@broadcom$(echo .)com \
--cc=hkallweit1@gmail$(echo .)com \
--cc=kabel@kernel$(echo .)org \
--cc=kuba@kernel$(echo .)org \
--cc=netdev@vger$(echo .)kernel.org \
--cc=pabeni@redhat$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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