Skip to contentSkip to conversation

net: ethernet: mediatek: convert to PHYLINK

PATCH Superseded René van Dorst 3 participants 12 messages Aug 23, 2019 – Aug 25, 2019

Subsystems (6)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover net: ethernet: mediatek: convert to PHYLINK

These patches converts mediatek driver to PHYLINK API.

v2->v3:
* Phylink improvements and clean-ups after review
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   | 529 ++++++++++++------
 drivers/net/ethernet/mediatek/mtk_eth_soc.h   |  68 ++-
 drivers/net/ethernet/mediatek/mtk_sgmii.c     |  65 ++-
 8 files changed, 477 insertions(+), 293 deletions(-)
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

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

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

--
v2->v3:
* Make link_down() similar as link_up() suggested by Russell King 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 | 424 +++++++++++---------
 drivers/net/ethernet/mediatek/mtk_eth_soc.h |  31 +-
 3 files changed, 265 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 +244 -180

595 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 v3 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

--
v2->v3:
* Redo validate(), it was totally wrong. Noticed by Russell King. 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  | 157 ++++++++++++++++---
 drivers/net/ethernet/mediatek/mtk_eth_soc.h  |  37 ++++-
 drivers/net/ethernet/mediatek/mtk_sgmii.c    |  65 +++++---
 4 files changed, 219 insertions(+), 115 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 +139 -18

238 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
#9 lore raw

PATCH v3 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.

--
v2->v3:
* no change
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
Tested-by on the v3 series
#10 lore raw
In reply to René van Dorst

tested on bpi-r2 (mt7623/mt7530) and bpi-r64 (mt7622/rtl8367)

as reported to rene directly rx-path needs some rework because current rx-speed on bpi-r2 is 865 Mbits/sec instead of ~940 Mbits/sec

regards Frank

Quoted 36 lines

Gesendet: Freitag, 23. August 2019 um 15:45 Uhr
Von: "René van Dorst" <[email protected]>
An: "John Crispin" <[email protected]>, "Sean Wang" <[email protected]>, "Nelson Chang" <[email protected]>, "David S . Miller" <[email protected]>, "Matthias Brugger" <[email protected]>
Cc: [email protected], [email protected], [email protected], [email protected], "Russell King" <[email protected]>, "Frank Wunderlich" <[email protected]>, "Stefan Roese" <[email protected]>, "René van Dorst" <[email protected]>
Betreff: [PATCH net-next v3 0/3] net: ethernet: mediatek: convert to PHYLINK

These patches converts mediatek driver to PHYLINK API.

v2->v3:
* Phylink improvements and clean-ups after review
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   | 529 ++++++++++++------
 drivers/net/ethernet/mediatek/mtk_eth_soc.h   |  68 ++-
 drivers/net/ethernet/mediatek/mtk_sgmii.c     |  65 ++-
 8 files changed, 477 insertions(+), 293 deletions(-)
Signature · 1 line
2.20.1
#11 lore raw

Hi Frank,

Quoting Frank Wunderlich <[email protected]>:

Quoted 2 lines

tested on bpi-r2 (mt7623/mt7530) and bpi-r64 (mt7622/rtl8367)

Thanks for testing!

Quoted 2 lines

as reported to rene directly rx-path needs some rework because current rx-speed on bpi-r2 is 865 Mbits/sec instead of ~940 Mbits/sec

I still think it is a result of the extra code in the rx path when mt76x8 was introduced.

Greats,

René

Quoted 42 lines

regards Frank

Quoted 36 lines

Gesendet: Freitag, 23. August 2019 um 15:45 Uhr
Von: "René van Dorst" <[email protected]>
An: "John Crispin" <[email protected]>, "Sean Wang" <[email protected]>, "Nelson Chang" <[email protected]>, "David S . Miller" <[email protected]>, "Matthias Brugger" <[email protected]>
Cc: [email protected], [email protected], [email protected], [email protected], "Russell King" <[email protected]>, "Frank Wunderlich" <[email protected]>, "Stefan Roese" <[email protected]>, "René van Dorst" <[email protected]>
Betreff: [PATCH net-next v3 0/3] net: ethernet: mediatek: convert to PHYLINK

These patches converts mediatek driver to PHYLINK API.

v2->v3:
* Phylink improvements and clean-ups after review
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   | 529 ++++++++++++------
 drivers/net/ethernet/mediatek/mtk_eth_soc.h   |  68 ++-
 drivers/net/ethernet/mediatek/mtk_sgmii.c     |  65 ++-
 8 files changed, 477 insertions(+), 293 deletions(-)

--
2.20.1

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#2 lore raw

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

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

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

--
v2->v3:
* Make link_down() similar as link_up() suggested by Russell King

Yep, almost there, but...

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

Quoted 8 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +7 -0
+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);

... this clears all bits _except_ for the tx and rx enable (which will remain set) - you probably wanted a ~ before the (.

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 v3 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 6 lines · René van Dorst
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -0
+	switch (state->interface) {
+	case PHY_INTERFACE_MODE_SGMII:
+		phylink_set(mask, 10baseT_Half);
+		phylink_set(mask, 10baseT_Full);
+		phylink_set(mask, 100baseT_Half);
+		phylink_set(mask, 100baseT_Full);

You also want 1000baseX_Full here - the connected PHY could have a fiber interface on it.

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

Quoted 3 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +2 -0
+		/* fall through */
+	case PHY_INTERFACE_MODE_TRGMII:
 		phylink_set(mask, 1000baseT_Full);

I don't know enough about this interface type to comment whether it should support 1000baseX_Full - if this is connected to a PHY that may support fiber, then it ought to set it.

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

Quoted 6 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -0
+		break;
+	case PHY_INTERFACE_MODE_2500BASEX:
+		phylink_set(mask, 2500baseX_Full);
+		/* fall through */
+	case PHY_INTERFACE_MODE_1000BASEX:
+		phylink_set(mask, 1000baseX_Full);

Both should be set. The reasoning here is that if you have a Fiberchannel 4Gbaud SFP plugged in and connected directly to the MAC, it can operate at either 2500Base-X or 1000Base-X. If we decide to operate at 2500Base-X, then PHY_INTERFACE_MODE_2500BASEX will be chosen. Otherwise, PHY_INTERFACE_MODE_1000BASEX will be used.

The user can use ethtool to control which interface mode is used by adjusting the advertise mask and/or placing the interface in manual mode and setting the speed directly. This will change the PHY_INTERFACE_MODE_xxxxBASEX (via phylink_helper_basex_speed()) between the two settings.

If we lose 2500baseX_Full when 1000Base-X is selected, the user will not be able to go back to 2500Base-X mode.

Yes, it's a little confusing and has slightly different rules from the other modes - partly due to phylink_helper_basex_speed(). These are the only interface modes that we dynamically switch between depending on the settings that the user configures via ethtool.

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 v3 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 19 lines · René van Dorst
Quoted 7 lines

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

--
v2->v3:
* Make link_down() similar as link_up() suggested by Russell King

Yep, almost there, but...

Quoted 8 lines

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

drivers/net/ethernet/mediatek/mtk_eth_soc.c +5 -0
+			      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));
Quoted 4 lines

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

Quoted 1 line
drivers/net/ethernet/mediatek/mtk_eth_soc.c +1 -0
+	mcr &= (MAC_MCR_TX_EN | MAC_MCR_RX_EN);

... this clears all bits _except_ for the tx and rx enable (which will remain set) - you probably wanted a ~ before the (.

Yes that is what it should be.
I only want to clear the TX_EN en RX_EN bits.

Greats,

René

Quoted 5 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

#6 lore raw

Re: [PATCH net-next v3 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 10 lines · René van Dorst

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

Quoted 6 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -0
+	switch (state->interface) {
+	case PHY_INTERFACE_MODE_SGMII:
+		phylink_set(mask, 10baseT_Half);
+		phylink_set(mask, 10baseT_Full);
+		phylink_set(mask, 100baseT_Half);
+		phylink_set(mask, 100baseT_Full);

You also want 1000baseX_Full here - the connected PHY could have a fiber interface on it.

Ok, I shall add that mode too.

Quoted 8 lines

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

Quoted 4 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +2 -0
+		/* fall through */
+	case PHY_INTERFACE_MODE_TRGMII:
 		phylink_set(mask, 1000baseT_Full);

I don't know enough about this interface type to comment whether it should support 1000baseX_Full - if this is connected to a PHY that may support fiber, then it ought to set it.

Mediatek calls it Turbo RGMII. It is a overclock version of RGMII mode. It is used between first GMAC and port 6 of the mt7530 switch. Can be used with an internal and an external mt7530 switch.

TRGMII speed are:
* mt7621: 1200Mbit
* mt7623: 2000Mbit and 2600Mbit.

I think that TRGMII is only used in a fixed-link situation in combination with a mt7530 switch and running and maximum speed/full duplex. So reporting 1000baseT_Full seems to me the right option.

Quoted 21 lines

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

Quoted 7 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -0
+		break;
+	case PHY_INTERFACE_MODE_2500BASEX:
+		phylink_set(mask, 2500baseX_Full);
+		/* fall through */
+	case PHY_INTERFACE_MODE_1000BASEX:
+		phylink_set(mask, 1000baseX_Full);

Both should be set. The reasoning here is that if you have a Fiberchannel 4Gbaud SFP plugged in and connected directly to the MAC, it can operate at either 2500Base-X or 1000Base-X. If we decide to operate at 2500Base-X, then PHY_INTERFACE_MODE_2500BASEX will be chosen. Otherwise, PHY_INTERFACE_MODE_1000BASEX will be used.

The user can use ethtool to control which interface mode is used by adjusting the advertise mask and/or placing the interface in manual mode and setting the speed directly. This will change the PHY_INTERFACE_MODE_xxxxBASEX (via phylink_helper_basex_speed()) between the two settings.

Quoted 8 lines

If we lose 2500baseX_Full when 1000Base-X is selected, the user will not be able to go back to 2500Base-X mode.

Yes, it's a little confusing and has slightly different rules from the other modes - partly due to phylink_helper_basex_speed(). These are the only interface modes that we dynamically switch between depending on the settings that the user configures via ethtool.

Thanks for this extra information.

I made a list for each mode what that mode should report back when chosen.

PHY_INTERFACE_MODE_SGMII:

	  10baseT_Half
	  10baseT_Full
	 100baseT_Half
	 100baseT_Full
	1000baseT_Full
	1000baseX_Full

PHY_INTERFACE_MODE_1000BASEX:
PHY_INTERFACE_MODE_2500BASEX:

	1000baseX_Full
	2500baseX_Full

PHY_INTERFACE_MODE_TRGMII:

	1000baseT_Full

PHY_INTERFACE_MODE_RGMII:
PHY_INTERFACE_MODE_RGMII_ID:
PHY_INTERFACE_MODE_RGMII_RXID:
PHY_INTERFACE_MODE_RGMII_TXID:

	  10baseT_Half
	  10baseT_Full
	 100baseT_Half
	 100baseT_Full
	1000baseT_Half
	1000baseT_Full
	1000baseX_Full

PHY_INTERFACE_MODE_GMII:

	  10baseT_Half
	  10baseT_Full
	 100baseT_Half
	 100baseT_Full
	1000baseT_Half
	1000baseT_Full

PHY_INTERFACE_MODE_MII:
PHY_INTERFACE_MODE_RMII:
PHY_INTERFACE_MODE_REVMII:

	 10baseT_Half
	 10baseT_Full
	100baseT_Half
	100baseT_Full

case PHY_INTERFACE_MODE_NA:

	  10baseT_Half
	  10baseT_Full
	 100baseT_Half
	 100baseT_Full
	1000baseT_Half
	1000baseT_Full
	1000baseX_Full
	2500baseX_Full

I think this is the full list.
Or do I miss something?

Greats,

René

Quoted 5 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 v3 2/3] net: ethernet: mediatek: Re-add support SGMII

Hi René,

Quoted 7 lines · René van Dorst

Hi Russell,

Mediatek calls it Turbo RGMII. It is a overclock version of RGMII mode. It is used between first GMAC and port 6 of the mt7530 switch. Can be used with
an internal and an external mt7530 switch.

Quoted 8 lines

TRGMII speed are:
* mt7621: 1200Mbit
* mt7623: 2000Mbit and 2600Mbit.

I think that TRGMII is only used in a fixed-link situation in combination with a
mt7530 switch and running and maximum speed/full duplex. So reporting 1000baseT_Full seems to me the right option.

I think we can ignore this one for the purposes of merging this patch set, since this seems to be specific to this setup. Neither 1000BaseT nor 1000BaseX fit very well, but we have to choose something.

Quoted 7 lines

PHY_INTERFACE_MODE_GMII:

	  10baseT_Half
	  10baseT_Full
	 100baseT_Half
	 100baseT_Full
	1000baseT_Half
	1000baseT_Full

I think GMII can be connected to a PHY that can convert to 1000BaseX, so should probably include that here too.

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
#8 lore raw

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

Hi Russell,

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

Quoted 31 lines

Hi René,

Quoted 7 lines · René van Dorst

Hi Russell,

Mediatek calls it Turbo RGMII. It is a overclock version of RGMII mode. It is used between first GMAC and port 6 of the mt7530 switch. Can be used with
an internal and an external mt7530 switch.

Quoted 8 lines

TRGMII speed are:
* mt7621: 1200Mbit
* mt7623: 2000Mbit and 2600Mbit.

I think that TRGMII is only used in a fixed-link situation in combination with a
mt7530 switch and running and maximum speed/full duplex. So reporting 1000baseT_Full seems to me the right option.

I think we can ignore this one for the purposes of merging this patch set, since this seems to be specific to this setup. Neither 1000BaseT nor 1000BaseX fit very well, but we have to choose something.

Quoted 7 lines

PHY_INTERFACE_MODE_GMII:

	  10baseT_Half
	  10baseT_Full
	 100baseT_Half
	 100baseT_Full
	1000baseT_Half
	1000baseT_Full
Quoted 3 lines

I think GMII can be connected to a PHY that can convert to 1000BaseX, so should probably include that here too.

Thanks for reviewing.
I shall add that too.

I send v4 today.

Greats,

René

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