netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Woudstra <ericwouds@gmail.com>
To: Russell King <linux@armlinux.org.uk>,
	Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Daniel Golle <daniel@makrotopia.org>,
	Frank Wunderlich <frank-w@public-files.de>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	Eric Woudstra <ericwouds@gmail.com>
Subject: [PATCH RFC net-next] net: phylink: add quirk for disabling in-band-status for mediatek pcs at 2500base-x
Date: Tue,  2 Jan 2024 08:43:26 +0100	[thread overview]
Message-ID: <20240102074326.1049179-1-ericwouds@gmail.com> (raw)

In follow up to: net: pcs: pcs-mtk-lynxi: use 2500Base-X without AN

MediaTek LynxI PCS, 2500Base-X will only work without inband status due to
hardware limitation.

I understand this patch probably will not get approved as it is now, but
perhaps with some pointers in the correct direction to follow, I can change
it so it could be. It does however get the result that the rtl8221b on a
sfp module functions correctly, with and without (as optical sfp) the phy
attached and without using a quirk/ethtool to disable auto-negotiation.

Introduce bool phylink_major_no_inband(pl,interface), a function similar to
bool phylink_phy_no_inband(phy). An option could be to use a function like
bool pcs->ops->supports_inband(interface), where if the function-pointer is
null, it means it is supported for all. This instead of using
of_device_is_compatible() inside the phylink_major_no_inband() function.

Code added to phylink_major_config():

When there is no PHY attached, pl->pcs_neg_mode is set to
PHYLINK_PCS_NEG_INBAND_DISABLED.

When there is a PHY attached, pl->cur_link_an_mode is set to MLO_AN_PHY.
To have the pcs function correctly with the rtl8221b, we need to do the
following to the in-band-status:

We need to disable it when interface of the pcs is set to 2500base-x,
but need it enable it when switched to sgmii.

So we get:

[...] mtk_soc_eth ... eth1: phy link up sgmii/1Gbps/Full/none/rx/tx
[...] mtk_soc_eth ... eth1: phylink_mac_config: mode=inband/sgmii/none
                                adv=00,00000000,00000000,00000000 pause=03

[...] mtk_soc_eth ... eth1: phy link up 2500base-x/2.5Gbps/Full/none/rx/tx
[...] mtk_soc_eth ... eth1: phylink_mac_config: mode=phy/2500base-x/none
                                adv=00,00000000,00008000,0000606f pause=03

Changes to be committed:
	modified:   drivers/net/phy/phylink.c

Signed-off-by: Eric Woudstra <ericwouds@gmail.com>
---
 drivers/net/phy/phylink.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 298dfd6982a5..6e443eb8ee46 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -1074,6 +1074,22 @@ static void phylink_pcs_an_restart(struct phylink *pl)
 		pl->pcs->ops->pcs_an_restart(pl->pcs);
 }
 
+static bool phylink_major_no_inband(struct phylink *pl, phy_interface_t interface)
+{
+	struct device_node *node = pl->config->dev->of_node;
+
+	if (!node)
+		return false;
+
+	if (!of_device_is_compatible(node, "mediatek,eth-mac"))
+		return false;
+
+	if (interface != PHY_INTERFACE_MODE_2500BASEX)
+		return false;
+
+	return true;
+}
+
 static void phylink_major_config(struct phylink *pl, bool restart,
 				  const struct phylink_link_state *state)
 {
@@ -1085,10 +1101,22 @@ static void phylink_major_config(struct phylink *pl, bool restart,
 
 	phylink_dbg(pl, "major config %s\n", phy_modes(state->interface));
 
+	if (phylink_major_no_inband(pl, state->interface) && (!!pl->phydev)) {
+		if (pl->cur_link_an_mode == MLO_AN_INBAND)
+			pl->cur_link_an_mode = MLO_AN_PHY;
+		else
+			/* restore mode if it was changed before */
+			pl->cur_link_an_mode = pl->cfg_link_an_mode;
+	}
+
 	pl->pcs_neg_mode = phylink_pcs_neg_mode(pl->cur_link_an_mode,
 						state->interface,
 						state->advertising);
 
+	if (phylink_major_no_inband(pl, state->interface) && !pl->phydev &&
+	    pl->pcs_neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)
+		pl->pcs_neg_mode = PHYLINK_PCS_NEG_INBAND_DISABLED;
+
 	if (pl->using_mac_select_pcs) {
 		pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
 		if (IS_ERR(pcs)) {
@@ -1218,6 +1246,9 @@ static void phylink_mac_pcs_get_state(struct phylink *pl,
 				      struct phylink_link_state *state)
 {
 	linkmode_copy(state->advertising, pl->link_config.advertising);
+	if (pl->pcs_neg_mode == PHYLINK_PCS_NEG_INBAND_DISABLED)
+		linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
+				   state->advertising);
 	linkmode_zero(state->lp_advertising);
 	state->interface = pl->link_config.interface;
 	state->rate_matching = pl->link_config.rate_matching;
-- 
2.42.1


             reply	other threads:[~2024-01-02  7:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02  7:43 Eric Woudstra [this message]
2024-01-02 10:52 ` [PATCH RFC net-next] net: phylink: add quirk for disabling in-band-status for mediatek pcs at 2500base-x Daniel Golle
2024-01-02 12:31   ` Eric Woudstra
2024-01-02 12:36 ` Russell King (Oracle)
2024-01-02 13:16   ` Eric Woudstra
2024-01-07 19:41   ` Eric Woudstra

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=20240102074326.1049179-1-ericwouds@gmail.com \
    --to=ericwouds@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=frank-w@public-files.de \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).