Skip to contentSkip to conversation

net: ethernet: mediatek: convert to PHYLINK

PATCH Superseded René van Dorst 3 participants 10 messages Aug 21, 2019 – Aug 27, 2019

Subsystems (6)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover net: ethernet: mediatek: convert to PHYLINK

These patches converts mediatek driver to PHYLINK API.

v1->v2:
* Rebase for mt76x8 changes
* Phylink improvements and clean-ups after review
* SGMII port doesn't support 2.5Gbit in SGMII mode only in BASE-X mode. Refactor the code.

René van Dorst (3):
net: ethernet: mediatek: Add basic PHYLINK support
net: ethernet: mediatek: Re-add support SGMII
dt-bindings: net: ethernet: Update mt7622 docs and dts to reflect the
new phylink API

 .../arm/mediatek/mediatek,sgmiisys.txt        |   2 -
 .../dts/mediatek/mt7622-bananapi-bpi-r64.dts  |  28 +-
 arch/arm64/boot/dts/mediatek/mt7622.dtsi      |   1 -
 drivers/net/ethernet/mediatek/Kconfig         |   2 +-
 drivers/net/ethernet/mediatek/mtk_eth_path.c  |  75 +--
 drivers/net/ethernet/mediatek/mtk_eth_soc.c   | 502 ++++++++++++------
 drivers/net/ethernet/mediatek/mtk_eth_soc.h   |  68 ++-
 drivers/net/ethernet/mediatek/mtk_sgmii.c     |  65 ++-
 8 files changed, 447 insertions(+), 296 deletions(-)

--.
2.20.1

#1 lore raw

PATCH v2 1/3 net: ethernet: mediatek: Add basic PHYLINK support

This convert the basics to PHYLINK API.
SGMII support is not in this patch.

--
v1->v2:
* Also report 1000Base-X support suggested by Russell King
* Reverse christmas on many places suggested by David Miller
* Rebase too pickup the mt76x8 changes.

---
 drivers/net/ethernet/mediatek/Kconfig       |   2 +-
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 422 +++++++++++---------
 drivers/net/ethernet/mediatek/mtk_eth_soc.h |  31 +-
 3 files changed, 263 insertions(+), 192 deletions(-)
drivers/net/ethernet/mediatek/Kconfig +1 -1
index b76cf2e1c9dc..4968352ba188 100644
@@ -9,7 +9,7 @@ if NET_VENDOR_MEDIATEK
 
 config NET_MEDIATEK_SOC
 	tristate "MediaTek SoC Gigabit Ethernet support"
-	select PHYLIB
+	select PHYLINK
 	---help---
 	  This driver supports the gigabit ethernet MACs in the
 	  MediaTek SoC family.
drivers/net/ethernet/mediatek/mtk_eth_soc.c +242 -180

593 lines not on this page · raw message

drivers/net/ethernet/mediatek/mtk_eth_soc.h +20 -11
index cc1466ae0926..7f5f541daad7 100644
@@ -14,6 +14,7 @@
 #include <linux/of_net.h>
 #include <linux/u64_stats_sync.h>
 #include <linux/refcount.h>
+#include <linux/phylink.h>
 
 #define MTK_QDMA_PAGE_SIZE	2048
 #define	MTK_MAX_RX_LENGTH	1536
@@ -330,12 +331,19 @@
 #define MAC_MCR_SPEED_100	BIT(2)
 #define MAC_MCR_FORCE_DPX	BIT(1)
 #define MAC_MCR_FORCE_LINK	BIT(0)
-#define MAC_MCR_FIXED_LINK	(MAC_MCR_MAX_RX_1536 | MAC_MCR_IPG_CFG | \
-				 MAC_MCR_FORCE_MODE | MAC_MCR_TX_EN | \
-				 MAC_MCR_RX_EN | MAC_MCR_BACKOFF_EN | \
-				 MAC_MCR_BACKPR_EN | MAC_MCR_FORCE_RX_FC | \
-				 MAC_MCR_FORCE_TX_FC | MAC_MCR_SPEED_1000 | \
-				 MAC_MCR_FORCE_DPX | MAC_MCR_FORCE_LINK)
+#define MAC_MCR_FORCE_LINK_DOWN	(MAC_MCR_FORCE_MODE)
+
+/* Mac status registers */
+#define MTK_MAC_MSR(x)		(0x10108 + (x * 0x100))
+#define MAC_MSR_EEE1G		BIT(7)
+#define MAC_MSR_EEE100M		BIT(6)
+#define MAC_MSR_RX_FC		BIT(5)
+#define MAC_MSR_TX_FC		BIT(4)
+#define MAC_MSR_SPEED_1000	BIT(3)
+#define MAC_MSR_SPEED_100	BIT(2)
+#define MAC_MSR_SPEED_MASK	(MAC_MSR_SPEED_1000 | MAC_MSR_SPEED_100)
+#define MAC_MSR_DPX		BIT(1)
+#define MAC_MSR_LINK		BIT(0)
 
 /* TRGMII RXC control register */
 #define TRGMII_RCK_CTRL		0x10300
@@ -858,22 +866,23 @@ struct mtk_eth {
 /* struct mtk_mac -	the structure that holds the info about the MACs of the
  *			SoC
  * @id:			The number of the MAC
- * @ge_mode:            Interface mode kept for setup restoring
+ * @interface:		Interface mode kept for detecting change in hw settings
  * @of_node:		Our devicetree node
  * @hw:			Backpointer to our main datastruture
  * @hw_stats:		Packet statistics counter
- * @trgmii		Indicate if the MAC uses TRGMII connected to internal
-			switch
  */
 struct mtk_mac {
 	int				id;
-	int				ge_mode;
+	phy_interface_t			interface;
+	unsigned int			mode;
+	int				speed;
 	struct device_node		*of_node;
+	struct phylink			*phylink;
+	struct phylink_config		phylink_config;
 	struct mtk_eth			*hw;
 	struct mtk_hw_stats		*hw_stats;
 	__be32				hwlro_ip[MTK_MAX_LRO_IP_CNT];
 	int				hwlro_ip_cnt;
-	bool				trgmii;
 };
 
 /* the struct describing the SoC. these are declared in the soc_xyz.c files */
Signature · 1 line
2.20.1
#4 lore raw

PATCH v2 2/3 net: ethernet: mediatek: Re-add support SGMII

In reply to René van Dorst

* Re-add SGMII support but now with PHYLINK API support
So the SGMII changes are more clear
* Move SGMII block setup from mtk_gmac_sgmii_path_setup() to mtk_mac_config()
* Merge mtk_setup_hw_path() into mtk_mac_config()
* Remove mediatek,physpeed property, fixed-link supports now any speed so speed = <2500>; is now valid with PHYLINK.
* Demagic SGMII register values
* Use phylink state to setup fixed-link mode

--
v1->v2:
* SGMII port only support SGMII at 1Gbit, 1000BASE-X and 2500BASE-X. Also SGMII mode only does auto-negotiation.
* Change validate() to support mt76x8 changes.

---
 drivers/net/ethernet/mediatek/mtk_eth_path.c |  75 +---------
 drivers/net/ethernet/mediatek/mtk_eth_soc.c  | 139 +++++++++++++++----
 drivers/net/ethernet/mediatek/mtk_eth_soc.h  |  37 ++++-
 drivers/net/ethernet/mediatek/mtk_sgmii.c    |  65 ++++++---
 4 files changed, 195 insertions(+), 121 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_path.c +4 -71
index 28960e4c4e43..ef11cf3d1ccc 100644
@@ -239,10 +239,9 @@ static int mtk_eth_mux_setup(struct mtk_eth *eth, int path)
 	return err;
 }
 
-static int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id)
+int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id)
 {
-	unsigned int val = 0;
-	int sid, err, path;
+	int err, path;
 
 	path = (mac_id == 0) ?  MTK_ETH_PATH_GMAC1_SGMII :
 				MTK_ETH_PATH_GMAC2_SGMII;
@@ -252,33 +251,10 @@ static int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id)
 	if (err)
 		return err;
 
-	/* The path GMAC to SGMII will be enabled once the SGMIISYS is being
-	 * setup done.
-	 */
-	regmap_read(eth->ethsys, ETHSYS_SYSCFG0, &val);
-
-	regmap_update_bits(eth->ethsys, ETHSYS_SYSCFG0,
-			   SYSCFG0_SGMII_MASK, ~(u32)SYSCFG0_SGMII_MASK);
-
-	/* Decide how GMAC and SGMIISYS be mapped */
-	sid = (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_SGMII)) ? 0 : mac_id;
-
-	/* Setup SGMIISYS with the determined property */
-	if (MTK_HAS_FLAGS(eth->sgmii->flags[sid], MTK_SGMII_PHYSPEED_AN))
-		err = mtk_sgmii_setup_mode_an(eth->sgmii, sid);
-	else
-		err = mtk_sgmii_setup_mode_force(eth->sgmii, sid);
-
-	if (err)
-		return err;
-
-	regmap_update_bits(eth->ethsys, ETHSYS_SYSCFG0,
-			   SYSCFG0_SGMII_MASK, val);
-
 	return 0;
 }
 
-static int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id)
+int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id)
 {
 	int err, path = 0;
 
@@ -296,7 +272,7 @@ static int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id)
 	return 0;
 }
 
-static int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id)
+int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id)
 {
 	int err, path;
 
@@ -311,46 +287,3 @@ static int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id)
 	return 0;
 }
 
-int mtk_setup_hw_path(struct mtk_eth *eth, int mac_id, int phymode)
-{
-	int err;
-
-	/* No mux'ing for MT7628/88 */
-	if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
-		return 0;
-
-	switch (phymode) {
-	case PHY_INTERFACE_MODE_TRGMII:
-	case PHY_INTERFACE_MODE_RGMII_TXID:
-	case PHY_INTERFACE_MODE_RGMII_RXID:
-	case PHY_INTERFACE_MODE_RGMII_ID:
-	case PHY_INTERFACE_MODE_RGMII:
-	case PHY_INTERFACE_MODE_MII:
-	case PHY_INTERFACE_MODE_REVMII:
-	case PHY_INTERFACE_MODE_RMII:
-		if (MTK_HAS_CAPS(eth->soc->caps, MTK_RGMII)) {
-			err = mtk_gmac_rgmii_path_setup(eth, mac_id);
-			if (err)
-				return err;
-		}
-		break;
-	case PHY_INTERFACE_MODE_SGMII:
-		if (MTK_HAS_CAPS(eth->soc->caps, MTK_SGMII)) {
-			err = mtk_gmac_sgmii_path_setup(eth, mac_id);
-			if (err)
-				return err;
-		}
-		break;
-	case PHY_INTERFACE_MODE_GMII:
-		if (MTK_HAS_CAPS(eth->soc->caps, MTK_GEPHY)) {
-			err = mtk_gmac_gephy_path_setup(eth, mac_id);
-			if (err)
-				return err;
-		}
-		break;
-	default:
-		break;
-	}
-
-	return 0;
-}
drivers/net/ethernet/mediatek/mtk_eth_soc.c +115 -24

214 lines not on this page · raw message

drivers/net/ethernet/mediatek/mtk_eth_soc.h +33 -4
index 7f5f541daad7..76bd12cb8150 100644
@@ -412,14 +412,38 @@
 /* Register to auto-negotiation restart */
 #define SGMSYS_PCS_CONTROL_1	0x0
 #define SGMII_AN_RESTART	BIT(9)
+#define SGMII_ISOLATE		BIT(10)
+#define SGMII_AN_ENABLE		BIT(12)
+#define SGMII_LINK_STATYS	BIT(18)
+#define SGMII_AN_ABILITY	BIT(19)
+#define SGMII_AN_COMPLETE	BIT(21)
+#define SGMII_PCS_FAULT		BIT(23)
+#define SGMII_AN_EXPANSION_CLR	BIT(30)
 
 /* Register to programmable link timer, the unit in 2 * 8ns */
 #define SGMSYS_PCS_LINK_TIMER	0x18
 #define SGMII_LINK_TIMER_DEFAULT	(0x186a0 & GENMASK(19, 0))
 
 /* Register to control remote fault */
-#define SGMSYS_SGMII_MODE	0x20
-#define SGMII_REMOTE_FAULT_DIS	BIT(8)
+#define SGMSYS_SGMII_MODE		0x20
+#define SGMII_IF_MODE_BIT0		BIT(0)
+#define SGMII_SPEED_DUPLEX_AN		BIT(1)
+#define SGMII_SPEED_10			0x0
+#define SGMII_SPEED_100			BIT(2)
+#define SGMII_SPEED_1000		BIT(3)
+#define SGMII_DUPLEX_FULL		BIT(4)
+#define SGMII_IF_MODE_BIT5		BIT(5)
+#define SGMII_REMOTE_FAULT_DIS		BIT(8)
+#define SGMII_CODE_SYNC_SET_VAL		BIT(9)
+#define SGMII_CODE_SYNC_SET_EN		BIT(10)
+#define SGMII_SEND_AN_ERROR_EN		BIT(11)
+#define SGMII_IF_MODE_MASK		GENMASK(5, 1)
+
+/* Register to set SGMII speed, ANA RG_ Control Signals III*/
+#define SGMSYS_ANA_RG_CS3	0x2028
+#define RG_PHY_SPEED_MASK	(BIT(2) | BIT(3))
+#define RG_PHY_SPEED_1_25G	0x0
+#define RG_PHY_SPEED_3_125G	BIT(2)
 
 /* Register to power up QPHY */
 #define SGMSYS_QPHY_PWR_STATE_CTRL 0xe8
@@ -897,7 +921,12 @@ u32 mtk_r32(struct mtk_eth *eth, unsigned reg);
 int mtk_sgmii_init(struct mtk_sgmii *ss, struct device_node *np,
 		   u32 ana_rgc3);
 int mtk_sgmii_setup_mode_an(struct mtk_sgmii *ss, int id);
-int mtk_sgmii_setup_mode_force(struct mtk_sgmii *ss, int id);
-int mtk_setup_hw_path(struct mtk_eth *eth, int mac_id, int phymode);
+int mtk_sgmii_setup_mode_force(struct mtk_sgmii *ss, int id,
+			       const struct phylink_link_state *state);
+void mtk_sgmii_restart_an(struct mtk_eth *eth, int mac_id);
+
+int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);
+int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id);
+int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
 
 #endif /* MTK_ETH_H */
drivers/net/ethernet/mediatek/mtk_sgmii.c +43 -22

100 lines not on this page · raw message

Signature · 1 line
2.20.1
#8 lore raw

PATCH v2 3/3 dt-bindings: net: ethernet: Update mt7622 docs and dts to reflect the new phylink API

In reply to René van Dorst

This patch the removes the recently added mediatek,physpeed property. Use the fixed-link property speed = <2500> to set the phy in 2.5Gbit. See mt7622-bananapi-bpi-r64.dts for a working example.

--
v1->v2:
* SGMII port only support BASE-X at 2.5Gbit.

---
 .../arm/mediatek/mediatek,sgmiisys.txt        |  2 --
 .../dts/mediatek/mt7622-bananapi-bpi-r64.dts  | 28 +++++++++++++------
 arch/arm64/boot/dts/mediatek/mt7622.dtsi      |  1 -
 3 files changed, 19 insertions(+), 12 deletions(-)
Documentation/devicetree/bindings/arm/mediatek/mediatek,sgmiisys.txt +0 -2
index f5518f26a914..30cb645c0e54 100644
@@ -9,8 +9,6 @@ Required Properties:
 	- "mediatek,mt7622-sgmiisys", "syscon"
 	- "mediatek,mt7629-sgmiisys", "syscon"
 - #clock-cells: Must be 1
-- mediatek,physpeed: Should be one of "auto", "1000" or "2500" to match up
-		     the capability of the target PHY.
 
 The SGMIISYS controller uses the common clk binding from
 Documentation/devicetree/bindings/clock/clock-bindings.txt
arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts +19 -9
index 710c5c3d87d3..83e10591e0e5 100644
@@ -115,24 +115,34 @@
 };
 
 &eth {
-	pinctrl-names = "default";
-	pinctrl-0 = <&eth_pins>;
 	status = "okay";
+	gmac0: mac@0 {
+		compatible = "mediatek,eth-mac";
+		reg = <0>;
+		phy-mode = "2500base-x";
+
+		fixed-link {
+			speed = <2500>;
+			full-duplex;
+			pause;
+		};
+	};
 
 	gmac1: mac@1 {
 		compatible = "mediatek,eth-mac";
 		reg = <1>;
-		phy-handle = <&phy5>;
+		phy-mode = "rgmii";
+
+		fixed-link {
+			speed = <1000>;
+			full-duplex;
+			pause;
+		};
 	};
 
-	mdio-bus {
+	mdio: mdio-bus {
 		#address-cells = <1>;
 		#size-cells = <0>;
-
-		phy5: ethernet-phy@5 {
-			reg = <5>;
-			phy-mode = "sgmii";
-		};
 	};
 };
 
arch/arm64/boot/dts/mediatek/mt7622.dtsi +0 -1
index d1e13d340e26..dac51e98204c 100644
@@ -931,6 +931,5 @@
 			     "syscon";
 		reg = <0 0x1b128000 0 0x3000>;
 		#clock-cells = <1>;
-		mediatek,physpeed = "2500";
 	};
 };
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH net-next v2 1/3] net: ethernet: mediatek: Add basic PHYLINK support

In reply to René van Dorst

drivers/net/ethernet/mediatek/mtk_eth_soc.c static void mtk_gmac0_rgmii_adjust(struct mtk_eth *eth, int speed) · line 339

Quoted 9 lines · René van Dorst
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -1
+static void mtk_mac_link_down(struct phylink_config *config, unsigned int mode,
+			      phy_interface_t interface)
+{
+	struct mtk_mac *mac = container_of(config, struct mtk_mac,
+					   phylink_config);
 
-	return 0;
+	mtk_w32(mac->hw, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(mac->id));
 }

You set the MAC_MCR_FORCE_MODE bit here...

drivers/net/ethernet/mediatek/mtk_eth_soc.c static void mtk_gmac0_rgmii_adjust(struct mtk_eth *eth, int speed) · line 351

Quoted 11 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +9 -0
+static void mtk_mac_link_up(struct phylink_config *config, unsigned int mode,
+			    phy_interface_t interface,
+			    struct phy_device *phy)
 {
+	struct mtk_mac *mac = container_of(config, struct mtk_mac,
+					   phylink_config);
+	u32 mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
 
+	mcr |= MAC_MCR_TX_EN | MAC_MCR_RX_EN;
+	mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
+}

Looking at this, a link_down() followed by a link_up() would result in this register containing MAC_MCR_FORCE_MODE | MAC_MCR_TX_EN | MAC_MCR_RX_EN ? Is that actually correct? (MAC_MCR_FORCE_LINK isn't set, so it looks to me like it still forces the link down.)

Note that link up/down forcing should not be done for in-band AN.

Quoted 33 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +29 -0
+static void mtk_validate(struct phylink_config *config,
+			 unsigned long *supported,
+			 struct phylink_link_state *state)
+{
+	struct mtk_mac *mac = container_of(config, struct mtk_mac,
+					   phylink_config);
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
 
+	if (state->interface != PHY_INTERFACE_MODE_NA &&
+	    state->interface != PHY_INTERFACE_MODE_MII &&
+	    state->interface != PHY_INTERFACE_MODE_GMII &&
+	    !(MTK_HAS_CAPS(mac->hw->soc->caps, MTK_RGMII) &&
+	      phy_interface_mode_is_rgmii(state->interface)) &&
+	    !(MTK_HAS_CAPS(mac->hw->soc->caps, MTK_TRGMII) &&
+	      !mac->id && state->interface == PHY_INTERFACE_MODE_TRGMII)) {
+		linkmode_zero(supported);
+		return;
 	}
 
+	phylink_set_port_modes(mask);
+	phylink_set(mask, Autoneg);
 
+	if (state->interface == PHY_INTERFACE_MODE_TRGMII) {
+		phylink_set(mask, 1000baseT_Full);
+	} else {
+		phylink_set(mask, 10baseT_Half);
+		phylink_set(mask, 10baseT_Full);
+		phylink_set(mask, 100baseT_Half);
+		phylink_set(mask, 100baseT_Full);
+
+		if (state->interface != PHY_INTERFACE_MODE_MII) {
+			phylink_set(mask, 1000baseT_Half);
+			phylink_set(mask, 1000baseT_Full);

drivers/net/ethernet/mediatek/mtk_eth_soc.c static void mtk_gmac0_rgmii_adjust(struct mtk_eth *eth, int speed) · line 395

Quoted 10 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +7 -0
+			phylink_set(mask, 1000baseX_Full);
+		}
+	}
 
+	phylink_set(mask, Pause);
+	phylink_set(mask, Asym_Pause);
 
+	linkmode_and(supported, supported, mask);
+	linkmode_and(state->advertising, state->advertising, mask);
 }

This looks fine.

Thanks.

Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#5 lore raw

Re: [PATCH net-next v2 2/3] net: ethernet: mediatek: Re-add support SGMII

In reply to René van Dorst

drivers/net/ethernet/mediatek/mtk_eth_soc.c static void mtk_validate(struct phylink_config *config, · line 458

Quoted 8 lines · René van Dorst
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -0
+	if (MTK_HAS_CAPS(mac->hw->soc->caps, MTK_SGMII)) {
+		if (state->interface != PHY_INTERFACE_MODE_2500BASEX) {
 			phylink_set(mask, 1000baseT_Full);
 			phylink_set(mask, 1000baseX_Full);
+		} else {
+			phylink_set(mask, 2500baseT_Full);
+			phylink_set(mask, 2500baseX_Full);
+		}

If you can dynamically switch between 1000BASE-X and 2500BASE-X, then you need to have both set. See mvneta.c:

        if (pp->comphy || state->interface != PHY_INTERFACE_MODE_2500BASEX) {
                phylink_set(mask, 1000baseT_Full);
                phylink_set(mask, 1000baseX_Full);
        }
        if (pp->comphy || state->interface == PHY_INTERFACE_MODE_2500BASEX) {
                phylink_set(mask, 2500baseT_Full);
                phylink_set(mask, 2500baseX_Full);
        }

What this is saying is, if we have a comphy (which is the serdes lane facing component, where the data rate is setup) then we can support both speeds (and so mask ends up with all four bits set.) Otherwise, we only support a single-speed (1000Gbps for non-2500BASE-X etc.)

Quoted 4 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +4 -0
+	} else {
+		if (state->interface == PHY_INTERFACE_MODE_TRGMII) {
+			phylink_set(mask, 1000baseT_Full);
+		} else {

drivers/net/ethernet/mediatek/mtk_eth_soc.c static void mtk_validate(struct phylink_config *config, · line 472

Quoted 10 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +10 -0
+			phylink_set(mask, 10baseT_Half);
+			phylink_set(mask, 10baseT_Full);
+			phylink_set(mask, 100baseT_Half);
+			phylink_set(mask, 100baseT_Full);
+
+			if (state->interface != PHY_INTERFACE_MODE_MII) {
+				phylink_set(mask, 1000baseT_Half);
+				phylink_set(mask, 1000baseT_Full);
+				phylink_set(mask, 1000baseX_Full);
+			}

I'm also wondering about the "MTK_HAS_CAPS(mac->hw->soc->caps, MTK_SGMII)" above.

(Here comes a reason why using SGMII to cover all single-lane serdes modes causes confusion - unfortunately, some folk use SGMII to describe all these modes. So, I'm going to use the terminology "Cisco SGMII" to mean exactly the SGMII format published by Cisco, "802.3 1000BASE-X" to mean the original IEEE 802.3 format running at 1.25Gbps, and "up-clocked 2500BASE-X" to mean the 3.125Gbps version of the 802.3 1000BASE-X protocol.)

Isn't this set for Cisco SGMII as well as for 802.3 1000BASE-X and the up-clocked 2500BASE-X modes?

If so, is there a reason why 10Mbps and 100Mbps speeds aren't supported on Cisco SGMII links?

Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#3 lore raw

Re: [PATCH net-next v2 1/3] net: ethernet: mediatek: Add basic PHYLINK support

In reply to Russell King - ARM Linux admin

Hi Russell,

Quoting Russell King - ARM Linux admin <[email protected]>:

Quoted 23 lines · René van Dorst

drivers/net/ethernet/mediatek/mtk_eth_soc.c static void mtk_gmac0_rgmii_adjust(struct mtk_eth *eth, int speed) · line 339

Quoted 10 lines

+static void mtk_mac_link_down(struct phylink_config *config, unsigned int mode,

drivers/net/ethernet/mediatek/mtk_eth_soc.c +5 -1
+			      phy_interface_t interface)
+{
+	struct mtk_mac *mac = container_of(config, struct mtk_mac,
+					   phylink_config);
 
-	return 0;
+	mtk_w32(mac->hw, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(mac->id));
 }

You set the MAC_MCR_FORCE_MODE bit here...

Quoted 9 lines

+static void mtk_mac_link_up(struct phylink_config *config, unsigned int mode,

drivers/net/ethernet/mediatek/mtk_eth_soc.c +5 -0
+			    phy_interface_t interface,
+			    struct phy_device *phy)
 {
+	struct mtk_mac *mac = container_of(config, struct mtk_mac,
+					   phylink_config);
+	u32 mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
Quoted 8 lines

drivers/net/ethernet/mediatek/mtk_eth_soc.c static void mtk_gmac0_rgmii_adjust(struct mtk_eth *eth, int speed) · line 351

Quoted 3 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +3 -0
+	mcr |= MAC_MCR_TX_EN | MAC_MCR_RX_EN;
+	mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
+}

Looking at this, a link_down() followed by a link_up() would result in this register containing MAC_MCR_FORCE_MODE | MAC_MCR_TX_EN | MAC_MCR_RX_EN ? Is that actually correct? (MAC_MCR_FORCE_LINK isn't set, so it looks to me like it still forces the link down.)

Thanks for reviewing.

Probably not.
I assumed that mac_config() is always called before link_up()

I simply can make it the opposite of link_up()

like this:
static void mtk_mac_link_down(struct phylink_config *config, unsigned int mode,
phy_interface_t interface)

{
      struct mtk_mac *mac = container_of(config, struct mtk_mac,
                                 phylink_config);
      u32 mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));

      mcr &= (MAC_MCR_TX_EN | MAC_MCR_RX_EN);
      mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
}
Quoted 3 lines

Note that link up/down forcing should not be done for in-band AN.

This means that mac_config() of the SGMII patch is also incorrect?

mac_config() always sets the MAC in a force mode.
But the SGMII block is set in AN.

Mainline code seems to do the same.
Puts the SGMII block in AN or forced mode and always set the MAC in forced mode.

Quoted 37 lines
Quoted 37 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +32 -0
+static void mtk_validate(struct phylink_config *config,
+			 unsigned long *supported,
+			 struct phylink_link_state *state)
+{
+	struct mtk_mac *mac = container_of(config, struct mtk_mac,
+					   phylink_config);
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
 
+	if (state->interface != PHY_INTERFACE_MODE_NA &&
+	    state->interface != PHY_INTERFACE_MODE_MII &&
+	    state->interface != PHY_INTERFACE_MODE_GMII &&
+	    !(MTK_HAS_CAPS(mac->hw->soc->caps, MTK_RGMII) &&
+	      phy_interface_mode_is_rgmii(state->interface)) &&
+	    !(MTK_HAS_CAPS(mac->hw->soc->caps, MTK_TRGMII) &&
+	      !mac->id && state->interface == PHY_INTERFACE_MODE_TRGMII)) {
+		linkmode_zero(supported);
+		return;
 	}
 
+	phylink_set_port_modes(mask);
+	phylink_set(mask, Autoneg);
 
+	if (state->interface == PHY_INTERFACE_MODE_TRGMII) {
+		phylink_set(mask, 1000baseT_Full);
+	} else {
+		phylink_set(mask, 10baseT_Half);
+		phylink_set(mask, 10baseT_Full);
+		phylink_set(mask, 100baseT_Half);
+		phylink_set(mask, 100baseT_Full);
+
+		if (state->interface != PHY_INTERFACE_MODE_MII) {
+			phylink_set(mask, 1000baseT_Half);
+			phylink_set(mask, 1000baseT_Full);
+			phylink_set(mask, 1000baseX_Full);
+		}
+	}
Quoted 8 lines

drivers/net/ethernet/mediatek/mtk_eth_soc.c static void mtk_gmac0_rgmii_adjust(struct mtk_eth *eth, int speed) · line 395

Quoted 6 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +4 -0
+	phylink_set(mask, Pause);
+	phylink_set(mask, Asym_Pause);
 
+	linkmode_and(supported, supported, mask);
+	linkmode_and(state->advertising, state->advertising, mask);
 }

This looks fine.

OK.

Quoted 6 lines

Thanks.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up

Greats,

René

#6 lore raw

Re: [PATCH net-next v2 2/3] net: ethernet: mediatek: Re-add support SGMII

In reply to Russell King - ARM Linux admin

Hi Russell,

Quoting Russell King - ARM Linux admin <[email protected]>:

Quoted 36 lines · René van Dorst

drivers/net/ethernet/mediatek/mtk_eth_soc.c static void mtk_validate(struct phylink_config *config, · line 458

Quoted 8 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -0
+	if (MTK_HAS_CAPS(mac->hw->soc->caps, MTK_SGMII)) {
+		if (state->interface != PHY_INTERFACE_MODE_2500BASEX) {
 			phylink_set(mask, 1000baseT_Full);
 			phylink_set(mask, 1000baseX_Full);
+		} else {
+			phylink_set(mask, 2500baseT_Full);
+			phylink_set(mask, 2500baseX_Full);
+		}

If you can dynamically switch between 1000BASE-X and 2500BASE-X, then you need to have both set. See mvneta.c:

        if (pp->comphy || state->interface != PHY_INTERFACE_MODE_2500BASEX) {
                phylink_set(mask, 1000baseT_Full);
                phylink_set(mask, 1000baseX_Full);
        }
        if (pp->comphy || state->interface == PHY_INTERFACE_MODE_2500BASEX) {
                phylink_set(mask, 2500baseT_Full);
                phylink_set(mask, 2500baseX_Full);
        }

What this is saying is, if we have a comphy (which is the serdes lane facing component, where the data rate is setup) then we can support both speeds (and so mask ends up with all four bits set.) Otherwise, we only support a single-speed (1000Gbps for non-2500BASE-X etc.)

Quoted 9 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +9 -0
+	} else {
+		if (state->interface == PHY_INTERFACE_MODE_TRGMII) {
+			phylink_set(mask, 1000baseT_Full);
+		} else {
+			phylink_set(mask, 10baseT_Half);
+			phylink_set(mask, 10baseT_Full);
+			phylink_set(mask, 100baseT_Half);
+			phylink_set(mask, 100baseT_Full);
+
Quoted 8 lines

drivers/net/ethernet/mediatek/mtk_eth_soc.c static void mtk_validate(struct phylink_config *config, · line 472

Quoted 5 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +5 -0
+			if (state->interface != PHY_INTERFACE_MODE_MII) {
+				phylink_set(mask, 1000baseT_Half);
+				phylink_set(mask, 1000baseT_Full);
+				phylink_set(mask, 1000baseX_Full);
+			}

I'm also wondering about the "MTK_HAS_CAPS(mac->hw->soc->caps, MTK_SGMII)" above.

This totally wrong.
MTK_HAS_CAPS(mac->hw->soc->caps, MTK_SGMII) tells me that the SOC has SGMII lane(s). Having a SGMII block doesn't mean that other functions aren't supported. I have to redo this!

Quoted 7 lines

(Here comes a reason why using SGMII to cover all single-lane serdes modes causes confusion - unfortunately, some folk use SGMII to describe all these modes. So, I'm going to use the terminology "Cisco SGMII" to mean exactly the SGMII format published by Cisco, "802.3 1000BASE-X" to mean the original IEEE 802.3 format running at 1.25Gbps, and "up-clocked 2500BASE-X" to mean the 3.125Gbps version of the 802.3 1000BASE-X protocol.)

Thanks for the explanation. In your previous review v1 you also explained it. I did change the forced modes for x-BaseX modes and auto negotiation for Cisco SGMII. But I seems to miss the link that I also have to improve this validation part.

Quoted 6 lines

Isn't this set for Cisco SGMII as well as for 802.3 1000BASE-X and the up-clocked 2500BASE-X modes?

If so, is there a reason why 10Mbps and 100Mbps speeds aren't supported on Cisco SGMII links?

I can only tell a bit about the mt7622 SOC, datasheet tells me that:

The SGMII is the interface between 10/100/1000/2500 Mbps PHY and Ethernet MAC, the spec is raised by Cisco in 1999, which is aims for pin reduction compare with the GMII. It uses 2 differential data pair for TX and RX with clock embedded bit stream to convey frame data and port ability information. The core leverages the 1000Base-X PCS and Auto-Negotiation from IEEE 802.3 specification (clause 36/37). This IP can support up to 3.125G baud for 2.5Gbps (proprietary 2500Base-X) data rate of MAC by overclocking.

Also features tells me: Support 10/100/1000/2500 Mbps in full duplex mode and 10/100 Mbps in half duplex mode.

I going make a new version.

Greats,

René

Quoted 4 lines

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up

#7 lore raw

Re: [PATCH net-next v2 2/3] net: ethernet: mediatek: Re-add support SGMII

Hi Rene,

Quoted 18 lines · René van Dorst

Quoting Russell King - ARM Linux admin <[email protected]>:

Quoted 5 lines

Isn't this set for Cisco SGMII as well as for 802.3 1000BASE-X and the up-clocked 2500BASE-X modes?

If so, is there a reason why 10Mbps and 100Mbps speeds aren't supported on Cisco SGMII links?

I can only tell a bit about the mt7622 SOC, datasheet tells me that:

The SGMII is the interface between 10/100/1000/2500 Mbps PHY and Ethernet MAC, the spec is raised by Cisco in 1999, which is aims for pin reduction compare with the GMII. It uses 2 differential data pair for TX and RX with clock embedded bit stream to convey frame data and port ability information. The core leverages the 1000Base-X PCS and Auto-Negotiation from IEEE 802.3 specification (clause 36/37). This IP can support up to 3.125G baud for 2.5Gbps
(proprietary 2500Base-X) data rate of MAC by overclocking.

Quoted 2 lines

Also features tells me: Support 10/100/1000/2500 Mbps in full duplex mode and 10/100 Mbps in half duplex mode.

Yep, that is what I'd expect. Thanks.

Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
maintainer Acked-by on v2 3/3
#9 lore raw

Re: [PATCH net-next v2 3/3] dt-bindings: net: ethernet: Update mt7622 docs and dts to reflect the new phylink API

In reply to René van Dorst
Quoted 4 lines · René van Dorst

This patch the removes the recently added mediatek,physpeed property. Use the fixed-link property speed = <2500> to set the phy in 2.5Gbit. See mt7622-bananapi-bpi-r64.dts for a working example.

Quoted 8 lines

--
v1->v2:
* SGMII port only support BASE-X at 2.5Gbit.

---
 .../arm/mediatek/mediatek,sgmiisys.txt        |  2 --

Bindings and dts files should be separate patches.

Quoted 3 lines
 .../dts/mediatek/mt7622-bananapi-bpi-r64.dts  | 28 +++++++++++++------
 arch/arm64/boot/dts/mediatek/mt7622.dtsi      |  1 -
 3 files changed, 19 insertions(+), 12 deletions(-)

In any case,