From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>, Heiner Kallweit <hkallweit1@gmail.com>
Cc: Alexander Couzens <lynxis@fe80.eu>,
Andrew Lunn <andrew+netdev@lunn.ch>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
Daniel Golle <daniel@makrotopia.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Florian Fainelli <florian.fainelli@broadcom.com>,
Ioana Ciornei <ioana.ciornei@nxp.com>,
Jakub Kicinski <kuba@kernel.org>,
Jose Abreu <Jose.Abreu@synopsys.com>,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
Marcin Wojtas <marcin.s.wojtas@gmail.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
netdev@vger.kernel.org, Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH RFC net-next 09/16] net: phylink: add pcs_inband_caps() method
Date: Tue, 26 Nov 2024 09:25:01 +0000 [thread overview]
Message-ID: <E1tFrob-005xQS-Hz@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <Z0WTpE8wkpjMiv_J@shell.armlinux.org.uk>
Add a pcs_inband_caps() method to query the PCS for its inband link
capabilities, and use this to determine whether link modes used with
optical SFPs can be supported.
When a PCS does not provide a method, we allow inband negotiation to
be either on or off, making this a no-op until the pcs_inband_caps()
method is implemented by a PCS driver.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/phy/phylink.c | 60 +++++++++++++++++++++++++++++++++++++++
include/linux/phylink.h | 17 +++++++++++
2 files changed, 77 insertions(+)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index e43a083cec57..ca52cb23187d 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -990,6 +990,15 @@ static void phylink_resolve_an_pause(struct phylink_link_state *state)
}
}
+static unsigned int phylink_pcs_inband_caps(struct phylink_pcs *pcs,
+ phy_interface_t interface)
+{
+ if (pcs && pcs->ops->pcs_inband_caps)
+ return pcs->ops->pcs_inband_caps(pcs, interface);
+
+ return 0;
+}
+
static void phylink_pcs_pre_config(struct phylink_pcs *pcs,
phy_interface_t interface)
{
@@ -1043,6 +1052,24 @@ static void phylink_pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode,
pcs->ops->pcs_link_up(pcs, neg_mode, interface, speed, duplex);
}
+/* Query inband for a specific interface mode, asking the MAC for the
+ * PCS which will be used to handle the interface mode.
+ */
+static unsigned int phylink_inband_caps(struct phylink *pl,
+ phy_interface_t interface)
+{
+ struct phylink_pcs *pcs;
+
+ if (!pl->mac_ops->mac_select_pcs)
+ return 0;
+
+ pcs = pl->mac_ops->mac_select_pcs(pl->config, interface);
+ if (!pcs)
+ return 0;
+
+ return phylink_pcs_inband_caps(pcs, interface);
+}
+
static void phylink_pcs_poll_stop(struct phylink *pl)
{
if (pl->cfg_link_an_mode == MLO_AN_INBAND)
@@ -2541,6 +2568,26 @@ int phylink_ethtool_ksettings_get(struct phylink *pl,
}
EXPORT_SYMBOL_GPL(phylink_ethtool_ksettings_get);
+static bool phylink_validate_pcs_inband_autoneg(struct phylink *pl,
+ phy_interface_t interface,
+ unsigned long *adv)
+{
+ unsigned int inband = phylink_inband_caps(pl, interface);
+ unsigned int mask;
+
+ /* If the PCS doesn't implement inband support, be permissive. */
+ if (!inband)
+ return true;
+
+ if (linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, adv))
+ mask = LINK_INBAND_ENABLE;
+ else
+ mask = LINK_INBAND_DISABLE;
+
+ /* Check whether the PCS implements the required mode */
+ return !!(inband & mask);
+}
+
/**
* phylink_ethtool_ksettings_set() - set the link settings
* @pl: a pointer to a &struct phylink returned from phylink_create()
@@ -2671,6 +2718,13 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
phylink_is_empty_linkmode(config.advertising))
return -EINVAL;
+ /* Validate the autonegotiation state. We don't have a PHY in this
+ * situation, so the PCS is the media-facing entity.
+ */
+ if (!phylink_validate_pcs_inband_autoneg(pl, config.interface,
+ config.advertising))
+ return -EINVAL;
+
mutex_lock(&pl->state_mutex);
pl->link_config.speed = config.speed;
pl->link_config.duplex = config.duplex;
@@ -3350,6 +3404,12 @@ static int phylink_sfp_config_optical(struct phylink *pl)
phylink_dbg(pl, "optical SFP: chosen %s interface\n",
phy_modes(interface));
+ if (!phylink_validate_pcs_inband_autoneg(pl, interface,
+ config.advertising)) {
+ phylink_err(pl, "autoneg setting not compatible with PCS");
+ return -EINVAL;
+ }
+
config.interface = interface;
/* Ignore errors if we're expecting a PHY to attach later */
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index 595139797acb..ef26111d0040 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -422,6 +422,7 @@ struct phylink_pcs {
/**
* struct phylink_pcs_ops - MAC PCS operations structure.
* @pcs_validate: validate the link configuration.
+ * @pcs_inband_caps: query inband support for interface mode.
* @pcs_enable: enable the PCS.
* @pcs_disable: disable the PCS.
* @pcs_pre_config: pre-mac_config method (for errata)
@@ -437,6 +438,8 @@ struct phylink_pcs {
struct phylink_pcs_ops {
int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
const struct phylink_link_state *state);
+ unsigned int (*pcs_inband_caps)(struct phylink_pcs *pcs,
+ phy_interface_t interface);
int (*pcs_enable)(struct phylink_pcs *pcs);
void (*pcs_disable)(struct phylink_pcs *pcs);
void (*pcs_pre_config)(struct phylink_pcs *pcs,
@@ -473,6 +476,20 @@ struct phylink_pcs_ops {
int pcs_validate(struct phylink_pcs *pcs, unsigned long *supported,
const struct phylink_link_state *state);
+/**
+ * pcs_inband_caps - query PCS in-band capabilities for interface mode.
+ * @pcs: a pointer to a &struct phylink_pcs.
+ * @interface: interface mode to be queried
+ *
+ * Returns zero if it is unknown what in-band signalling is supported by the
+ * PHY (e.g. because the PHY driver doesn't implement the method.) Otherwise,
+ * returns a bit mask of the LINK_INBAND_* values from
+ * &enum link_inband_signalling to describe which inband modes are supported
+ * for this interface mode.
+ */
+unsigned int pcs_inband_caps(struct phylink_pcs *pcs,
+ phy_interface_t interface);
+
/**
* pcs_enable() - enable the PCS.
* @pcs: a pointer to a &struct phylink_pcs.
--
2.30.2
next prev parent reply other threads:[~2024-11-26 9:36 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-26 9:23 [PATCH RFC net-next 00/16] net: add negotiation of in-band capabilities Russell King (Oracle)
2024-11-26 9:24 ` [PATCH RFC net-next 01/16] net: phylink: pass phylink and pcs into phylink_pcs_neg_mode() Russell King (Oracle)
2024-11-26 20:01 ` Andrew Lunn
2024-11-26 9:24 ` [PATCH RFC net-next 02/16] net: phylink: split cur_link_an_mode into requested and active Russell King (Oracle)
2024-11-26 20:02 ` Andrew Lunn
2024-11-26 9:24 ` [PATCH RFC net-next 03/16] net: phylink: add debug for phylink_major_config() Russell King (Oracle)
2024-11-26 20:03 ` Andrew Lunn
2024-11-26 9:24 ` [PATCH RFC net-next 04/16] net: phy: add phy_inband_caps() Russell King (Oracle)
2024-11-26 20:56 ` Andrew Lunn
2024-11-26 9:24 ` [PATCH RFC net-next 05/16] net: phy: bcm84881: implement phy_inband_caps() method Russell King (Oracle)
2024-11-26 20:57 ` Andrew Lunn
2024-11-26 9:24 ` [PATCH RFC net-next 06/16] net: phy: marvell: " Russell King (Oracle)
2024-11-26 20:58 ` Andrew Lunn
2024-11-26 9:24 ` [PATCH RFC net-next 07/16] net: phy: add phy_config_inband() Russell King (Oracle)
2024-11-26 21:00 ` Andrew Lunn
2024-11-26 9:24 ` [PATCH RFC net-next 08/16] net: phy: marvell: implement config_inband() method Russell King (Oracle)
2024-11-26 21:00 ` Andrew Lunn
2024-11-26 9:25 ` Russell King (Oracle) [this message]
2024-11-26 21:05 ` [PATCH RFC net-next 09/16] net: phylink: add pcs_inband_caps() method Andrew Lunn
2024-11-26 9:25 ` [PATCH RFC net-next 10/16] net: mvneta: implement " Russell King (Oracle)
2024-11-26 21:06 ` Andrew Lunn
2024-11-26 9:25 ` [PATCH RFC net-next 11/16] net: mvpp2: " Russell King (Oracle)
2024-11-26 21:07 ` Andrew Lunn
2024-11-26 9:25 ` [PATCH RFC net-next 12/16] net: pcs: pcs-lynx: " Russell King (Oracle)
2024-11-27 14:08 ` Maxime Chevallier
2024-11-26 9:25 ` [PATCH RFC net-next 13/16] net: pcs: pcs-mtk-lynxi: " Russell King (Oracle)
2024-11-26 9:25 ` [PATCH RFC net-next 14/16] net: pcs: xpcs: " Russell King (Oracle)
2024-11-26 9:25 ` [PATCH RFC net-next 15/16] net: phylink: add negotiation of in-band capabilities Russell King (Oracle)
2024-11-26 21:18 ` Andrew Lunn
2024-11-26 21:43 ` Russell King (Oracle)
2024-11-29 23:41 ` kernel test robot
2024-11-26 9:25 ` [PATCH RFC net-next 16/16] net: phylink: remove phylink_phy_no_inband() Russell King (Oracle)
2024-11-26 21:19 ` Andrew Lunn
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=E1tFrob-005xQS-Hz@rmk-PC.armlinux.org.uk \
--to=rmk+kernel@armlinux.org.uk \
--cc=Jose.Abreu@synopsys.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=angelogioacchino.delregno@collabora.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=florian.fainelli@broadcom.com \
--cc=hkallweit1@gmail.com \
--cc=ioana.ciornei@nxp.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=lynxis@fe80.eu \
--cc=marcin.s.wojtas@gmail.com \
--cc=matthias.bgg@gmail.com \
--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.