netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Yang <mmyangfl@gmail.com>
To: mmyangfl@gmail.com
Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v4] net: mv643xx_eth: support MII/GMII/RGMII modes for Kirkwood
Date: Sat,  1 Oct 2022 06:25:39 +0800	[thread overview]
Message-ID: <20220930222540.966357-1-mmyangfl@gmail.com> (raw)
In-Reply-To: <20220930213534.962336-1-mmyangfl@gmail.com>

Support mode switch properly, which is not available before.

If SoC has two Ethernet controllers, by setting both of them into MII
mode, the first controller enters GMII mode, while the second
controller is effectively disabled. This requires configuring (and
maybe enabling) the second controller in the device tree, even though
it cannot be used.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
v2: clarify modes work on controllers, read default value from PSC1
v3: Kirkwood only
v4: cleanup
 drivers/net/ethernet/marvell/mv643xx_eth.c | 57 +++++++++++++++++++---
 1 file changed, 51 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index b6be0552a..4d4ee36b5 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -108,6 +108,7 @@ static char mv643xx_eth_driver_version[] = "1.4";
 #define TXQ_COMMAND			0x0048
 #define TXQ_FIX_PRIO_CONF		0x004c
 #define PORT_SERIAL_CONTROL1		0x004c
+#define  RGMII_EN			0x00000008
 #define  CLK125_BYPASS_EN		0x00000010
 #define TX_BW_RATE			0x0050
 #define TX_BW_MTU			0x0058
@@ -1215,6 +1216,7 @@ static void mv643xx_eth_adjust_link(struct net_device *dev)
 	             DISABLE_AUTO_NEG_SPEED_GMII |
 		     DISABLE_AUTO_NEG_FOR_FLOW_CTRL |
 		     DISABLE_AUTO_NEG_FOR_DUPLEX;
+	u32 psc1r;
 
 	if (dev->phydev->autoneg == AUTONEG_ENABLE) {
 		/* enable auto negotiation */
@@ -1245,6 +1247,38 @@ static void mv643xx_eth_adjust_link(struct net_device *dev)
 
 out_write:
 	wrlp(mp, PORT_SERIAL_CONTROL, pscr);
+
+	if (dev->dev->of_node &&
+	    of_device_is_compatible(dev->dev->of_node,
+				    "marvell,kirkwood-eth-port")) {
+		psc1r = rdlp(mp, PORT_SERIAL_CONTROL1);
+		/* On Kirkwood with two Ethernet controllers, if both of them
+		 * have RGMII_EN disabled, the first controller will be in GMII
+		 * mode and the second one is effectively disabled, instead of
+		 * two MII interfaces.
+		 *
+		 * To enable GMII in the first controller, the second one must
+		 * also be configured (and may be enabled) with RGMII_EN
+		 * disabled too, even though it cannot be used at all.
+		 */
+		switch (dev->phydev->interface) {
+		case PHY_INTERFACE_MODE_MII:
+		case PHY_INTERFACE_MODE_GMII:
+			psc1r &= ~RGMII_EN;
+			break;
+		case PHY_INTERFACE_MODE_RGMII:
+		case PHY_INTERFACE_MODE_RGMII_ID:
+		case PHY_INTERFACE_MODE_RGMII_RXID:
+		case PHY_INTERFACE_MODE_RGMII_TXID:
+			psc1r |= RGMII_EN;
+			break;
+		default:
+			/* Unknown; don't touch */
+			break;
+		}
+
+		wrlp(mp, PORT_SERIAL_CONTROL1, psc1r);
+	}
 }
 
 /* statistics ***************************************************************/
@@ -2972,15 +3006,26 @@ static int get_phy_mode(struct mv643xx_eth_private *mp)
 	phy_interface_t iface;
 	int err;
 
-	if (dev->of_node)
+	if (dev->of_node) {
 		err = of_get_phy_mode(dev->of_node, &iface);
+		if (!err)
+			return iface;
+	}
+
+	/* Read the interface state in the PSC1 */
+	if (rdlp(mp, PORT_SERIAL_CONTROL1) & RGMII_EN)
+		return PHY_INTERFACE_MODE_RGMII;
 
-	/* Historical default if unspecified. We could also read/write
-	 * the interface state in the PSC1
+	/* Modes of two devices may interact on Kirkwood. Currently there is no
+	 * way to detect another device within this scope; blindly set MII
+	 * here.
 	 */
-	if (!dev->of_node || err)
-		iface = PHY_INTERFACE_MODE_GMII;
-	return iface;
+	if (dev->of_node &&
+	    of_device_is_compatible(dev->of_node, "marvell,kirkwood-eth"))
+		return PHY_INTERFACE_MODE_MII;
+
+	/* Historical default if unspecified */
+	return PHY_INTERFACE_MODE_GMII;
 }
 
 static struct phy_device *phy_scan(struct mv643xx_eth_private *mp,
-- 
2.35.1


  reply	other threads:[~2022-09-30 22:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-30 19:49 [PATCH] net: mv643xx_eth: support MII/GMII/RGMII modes David Yang
2022-09-30 20:28 ` Andrew Lunn
2022-09-30 20:39   ` [PATCH v2] " David Yang
2022-10-04  8:52     ` Paolo Abeni
2022-09-30 20:47   ` [PATCH] " Yangfl
2022-09-30 21:05     ` Andrew Lunn
2022-09-30 21:35       ` [PATCH v3] net: mv643xx_eth: support MII/GMII/RGMII modes for Kirkwood David Yang
2022-09-30 22:25         ` David Yang [this message]
2022-10-01  0:59           ` [PATCH v4] " Jakub Kicinski
2022-10-01  8:42             ` [PATCH v5] " David Yang

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=20220930222540.966357-1-mmyangfl@gmail.com \
    --to=mmyangfl@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sebastian.hesselbarth@gmail.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).