Skip to contentSkip to conversation

: net: dsa: mt7530: support MT7530 in the MT7621 SoC

PATCH In review [email protected] 4 participants 11 messages Jan 30, 2019

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

v4 cover : net: dsa: mt7530: support MT7530 in the MT7621 SoC

This is the fourth version of a patch series supporting the MT7530 switch as used in the MediaTek MT7621 SoC. Unlike the MediaTek MT7623 the MT7621 is built around a dual core MIPS CPU architecture. But inside it uses basically the same 7530 switch.

This series resolves all issues I had with previous versions, and I can now reliably use the driver on a 7621 SoC platform. These patches were generated against linux-5.0-rc4.

The first patch enables support for the existing kernel mediatek ethernet driver on the MT7621 SoC. This support is from Bjørn Mork, with an update and fix by me. Using this driver fixed a number of problems I had (TX checksums, large RX packet drop) over the staging driver (drivers/staging/mt7621-eth).

Patch 2 modifies the mt7530 DSA driver to support the 7530 switch as implemented in the Mediatek MT7621 SoC. The last patch updates the devicetree bindings to reflect the new support in the mt7530 driver.

There is no real dependencies between the patches, so they can be taken independantly.

Creating a new binding for the MT7621 seems like the only viable approach to distinguish between a stand alone 7530 switch, the silicon module in the MT7623 SoC and the silicon in the MT7621. Certainly the 7530 ID register in the MT7623 and MT7621 returns the same value, "0x7530001".

Looking at the mt7530.c DSA driver it might make some sense to convert the existing "mediatek,mcm" binding to something like "mediatek,mt7623" to be consistent with this new MT7621 support. As far as I can tell this is the intention of this binding.

 Documentation/devicetree/bindings/net/dsa/mt7530.txt |    6 -
 drivers/net/dsa/mt7530.c                             |   96 +++++++++++--------
 drivers/net/dsa/mt7530.h                             |    9 +
 drivers/net/ethernet/mediatek/Kconfig                |    2 
 drivers/net/ethernet/mediatek/mtk_eth_soc.c          |   48 ++++++++-
 drivers/net/ethernet/mediatek/mtk_eth_soc.h          |    4 
 6 files changed, 117 insertions(+), 48 deletions(-)

v1: initial patch series
v2: rebase to linux-5.0-rc2
include mediatek ethernet driver changes
use devicetree binding to identify platform
v3: dropped mediatek ethernet driver auto negotiate patch
change devicetree binding text as per feedback rebase onto 5.0-rc3
v4: simplify by using of_device_get_match_data()
fix casting for 7530/7621 ID to be 32 and 64 bit clean add review-by tag
rebase onto 5.0-rc4

#1 lore raw

PATCH v4 1/3 net: ethernet: mediatek: support MT7621 SoC ethernet hardware

From: Bjørn Mork <[email protected]>

The Mediatek MT7621 SoC contains the same ethernet hardware module as used on a number of other MediaTek SoC parts. There are some minor differences to deal with but we can use the same driver to support them all.

This patch is based on work by Bjørn Mork <[email protected]>, and his original patch is at:

https://github.com/bmork/LEDE/commit/3293bc63f5461ca1eb0bbc4ed90145335e7e3404

There is an additional compatible devicetree type added, and the primary change to the code required is to support a single interrupt (for both RX and TX interrupts).

[[email protected]: rebase to mainline and irq handler fix]
---
 drivers/net/ethernet/mediatek/Kconfig       |  2 +-
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 48 ++++++++++++++++++---
 drivers/net/ethernet/mediatek/mtk_eth_soc.h |  4 ++
 3 files changed, 46 insertions(+), 8 deletions(-)

v2: first in series for this change
v3: rebase onto 5.0-rc3
v4: rebase onto 5.0-rc4

drivers/net/ethernet/mediatek/Kconfig +1 -1
index f9149d2a4694..43656f961891 100644
@@ -1,6 +1,6 @@
 config NET_VENDOR_MEDIATEK
 	bool "MediaTek ethernet driver"
-	depends on ARCH_MEDIATEK
+	depends on ARCH_MEDIATEK || SOC_MT7621
 	---help---
 	  If you have a Mediatek SoC with ethernet, say Y.
 
drivers/net/ethernet/mediatek/mtk_eth_soc.c +41 -7

79 lines not on this page · raw message

drivers/net/ethernet/mediatek/mtk_eth_soc.h +4 -0
index 46819297fc3e..f7501997cea0 100644
@@ -363,6 +363,7 @@
 #define ETHSYS_CHIPID4_7	0x4
 #define MT7623_ETH		7623
 #define MT7622_ETH		7622
+#define MT7621_ETH		7621
 
 /* ethernet subsystem config register */
 #define ETHSYS_SYSCFG0		0x14
@@ -488,6 +489,8 @@ enum mtk_clks_map {
 				 BIT(MTK_CLK_SGMII_CDR_FB) | \
 				 BIT(MTK_CLK_SGMII_CK) | \
 				 BIT(MTK_CLK_ETH2PLL))
+#define MT7621_CLKS_BITMAP	(0)
+
 enum mtk_dev_state {
 	MTK_HW_INIT,
 	MTK_RESETTING
@@ -567,6 +570,7 @@ struct mtk_rx_ring {
 #define MTK_DUAL_GMAC_SHARED_SGMII	(BIT(11) | MTK_GMAC1_SGMII | \
 					 MTK_GMAC2_SGMII)
 #define MTK_HWLRO			BIT(12)
+#define MTK_SHARED_INT			BIT(13)
 #define MTK_HAS_CAPS(caps, _x)		(((caps) & (_x)) == (_x))
 
 /* struct mtk_eth_data -	This is the structure holding all differences
Signature · 1 line
2.17.1
#4 lore raw

PATCH v4 2/3 net: dsa: mt7530: support the 7530 switch on the Mediatek MT7621 SoC

In reply to [email protected]

From: Greg Ungerer <[email protected]>

The MediaTek MT7621 SoC device contains a 7530 switch, and the existing linux kernel 7530 DSA switch driver can be used with it.

The bulk of the changes required stem from the 7621 having different regulator and pad setup. The existing setup of these in the 7530 driver appears to be very specific to its implemtation in the Mediatek 7623 SoC. (Not entirely surprising given the 7623 is a quad core ARM based SoC, and the 7621 is a dual core, dual thread MIPS based SoC).

Create a new devicetree type, "mediatek,mt7621", to support the 7530 switch in the 7621 SoC. There appears to be no usable ID register to distinguish it from a 7530 in other hardware at runtime. This is used to carry out the appropriate configuration and setup.

---
 drivers/net/dsa/mt7530.c | 96 ++++++++++++++++++++++++----------------
 drivers/net/dsa/mt7530.h |  9 ++++
 2 files changed, 66 insertions(+), 39 deletions(-)

v1: initial patch
v2: use separate devicetree binding
v3: rebase onto 5.0-rc3
v4: simplify by using of_device_get_match_data()
fix casting for 7530/7621 ID to be 32 and 64 bit clean rebase onto 5.0-rc4

drivers/net/dsa/mt7530.c +57 -39
index a8a2c728afba..c2b61500f958 100644
@@ -621,17 +621,19 @@ static void mt7530_adjust_link(struct dsa_switch *ds, int port,
 	struct mt7530_priv *priv = ds->priv;
 
 	if (phy_is_pseudo_fixed_link(phydev)) {
-		dev_dbg(priv->dev, "phy-mode for master device = %x\n",
-			phydev->interface);
-
-		/* Setup TX circuit incluing relevant PAD and driving */
-		mt7530_pad_clk_setup(ds, phydev->interface);
-
-		/* Setup RX circuit, relevant PAD and driving on the host
-		 * which must be placed after the setup on the device side is
-		 * all finished.
-		 */
-		mt7623_pad_clk_setup(ds);
+		if (priv->id == ID_MT7530) {
+			dev_dbg(priv->dev, "phy-mode for master device = %x\n",
+				phydev->interface);
+
+			/* Setup TX circuit incluing relevant PAD and driving */
+			mt7530_pad_clk_setup(ds, phydev->interface);
+
+			/* Setup RX circuit, relevant PAD and driving on the
+			 * host which must be placed after the setup on the
+			 * device side is all finished.
+			 */
+			mt7623_pad_clk_setup(ds);
+		}
 	} else {
 		u16 lcl_adv = 0, rmt_adv = 0;
 		u8 flowctrl;
@@ -687,6 +689,10 @@ mt7530_cpu_port_enable(struct mt7530_priv *priv,
 	/* Unknown unicast frame fordwarding to the cpu port */
 	mt7530_set(priv, MT7530_MFC, UNU_FFP(BIT(port)));
 
+	/* Set CPU port number */
+	if (priv->id == ID_MT7621)
+		mt7530_rmw(priv, MT7530_MFC, CPU_MASK, CPU_EN | CPU_PORT(port));
+
 	/* CPU port gets connected to all user ports of
 	 * the switch
 	 */
@@ -1219,24 +1225,27 @@ mt7530_setup(struct dsa_switch *ds)
 	 * as two netdev instances.
 	 */
 	dn = ds->ports[MT7530_CPU_PORT].master->dev.of_node->parent;
-	priv->ethernet = syscon_node_to_regmap(dn);
-	if (IS_ERR(priv->ethernet))
-		return PTR_ERR(priv->ethernet);
 
-	regulator_set_voltage(priv->core_pwr, 1000000, 1000000);
-	ret = regulator_enable(priv->core_pwr);
-	if (ret < 0) {
-		dev_err(priv->dev,
-			"Failed to enable core power: %d\n", ret);
-		return ret;
-	}
+	if (priv->id == ID_MT7530) {
+		priv->ethernet = syscon_node_to_regmap(dn);
+		if (IS_ERR(priv->ethernet))
+			return PTR_ERR(priv->ethernet);
+
+		regulator_set_voltage(priv->core_pwr, 1000000, 1000000);
+		ret = regulator_enable(priv->core_pwr);
+		if (ret < 0) {
+			dev_err(priv->dev,
+				"Failed to enable core power: %d\n", ret);
+			return ret;
+		}
 
-	regulator_set_voltage(priv->io_pwr, 3300000, 3300000);
-	ret = regulator_enable(priv->io_pwr);
-	if (ret < 0) {
-		dev_err(priv->dev, "Failed to enable io pwr: %d\n",
-			ret);
-		return ret;
+		regulator_set_voltage(priv->io_pwr, 3300000, 3300000);
+		ret = regulator_enable(priv->io_pwr);
+		if (ret < 0) {
+			dev_err(priv->dev, "Failed to enable io pwr: %d\n",
+				ret);
+			return ret;
+		}
 	}
 
 	/* Reset whole chip through gpio pin or memory-mapped registers for
@@ -1326,6 +1335,13 @@ static const struct dsa_switch_ops mt7530_switch_ops = {
 	.port_vlan_del		= mt7530_port_vlan_del,
 };
 
+static const struct of_device_id mt7530_of_match[] = {
+	{ .compatible = "mediatek,mt7621", .data = (void *)ID_MT7621, },
+	{ .compatible = "mediatek,mt7530", .data = (void *)ID_MT7530, },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, mt7530_of_match);
+
 static int
 mt7530_probe(struct mdio_device *mdiodev)
 {
@@ -1356,13 +1372,21 @@ mt7530_probe(struct mdio_device *mdiodev)
 		}
 	}
 
-	priv->core_pwr = devm_regulator_get(&mdiodev->dev, "core");
-	if (IS_ERR(priv->core_pwr))
-		return PTR_ERR(priv->core_pwr);
+	/* Get the hardware identifier from the devicetree node.
+	 * We will need it for some of the clock and regulator setup.
+	 */
+	priv->id = (unsigned int)(unsigned long)
+		of_device_get_match_data(&mdiodev->dev);
 
-	priv->io_pwr = devm_regulator_get(&mdiodev->dev, "io");
-	if (IS_ERR(priv->io_pwr))
-		return PTR_ERR(priv->io_pwr);
+	if (priv->id == ID_MT7530) {
+		priv->core_pwr = devm_regulator_get(&mdiodev->dev, "core");
+		if (IS_ERR(priv->core_pwr))
+			return PTR_ERR(priv->core_pwr);
+
+		priv->io_pwr = devm_regulator_get(&mdiodev->dev, "io");
+		if (IS_ERR(priv->io_pwr))
+			return PTR_ERR(priv->io_pwr);
+	}
 
 	/* Not MCM that indicates switch works as the remote standalone
 	 * integrated circuit so the GPIO pin would be used to complete
@@ -1408,12 +1432,6 @@ mt7530_remove(struct mdio_device *mdiodev)
 	mutex_destroy(&priv->reg_mutex);
 }
 
-static const struct of_device_id mt7530_of_match[] = {
-	{ .compatible = "mediatek,mt7530" },
-	{ /* sentinel */ },
-};
-MODULE_DEVICE_TABLE(of, mt7530_of_match);
-
 static struct mdio_driver mt7530_mdio_driver = {
 	.probe  = mt7530_probe,
 	.remove = mt7530_remove,
drivers/net/dsa/mt7530.h +9 -0
index d9b407a22a58..a95ed958df5b 100644
@@ -19,6 +19,11 @@
 #define MT7530_NUM_FDB_RECORDS		2048
 #define MT7530_ALL_MEMBERS		0xff
 
+enum {
+	ID_MT7530 = 0,
+	ID_MT7621 = 1,
+};
+
 #define	NUM_TRGMII_CTRL			5
 
 #define TRGMII_BASE(x)			(0x10000 + (x))
@@ -36,6 +41,9 @@
 #define  UNM_FFP(x)			(((x) & 0xff) << 16)
 #define  UNU_FFP(x)			(((x) & 0xff) << 8)
 #define  UNU_FFP_MASK			UNU_FFP(~0)
+#define  CPU_EN				BIT(7)
+#define  CPU_PORT(x)			((x) << 4)
+#define  CPU_MASK			(0xf << 4)
 
 /* Registers for address table access */
 #define MT7530_ATA1			0x74
@@ -430,6 +438,7 @@ struct mt7530_priv {
 	struct regulator	*core_pwr;
 	struct regulator	*io_pwr;
 	struct gpio_desc	*reset;
+	unsigned int		id;
 	bool			mcm;
 
 	struct mt7530_port	ports[MT7530_NUM_PORTS];
Signature · 1 line
2.17.1
#7 lore raw

PATCH v4 3/3 dt-bindings: net: dsa: add new MT7530 binding to support MT7621

In reply to [email protected]

From: Greg Ungerer <[email protected]>

Add devicetree binding to support the compatible mt7530 switch as used in the MediaTek MT7621 SoC.

---
 Documentation/devicetree/bindings/net/dsa/mt7530.txt | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

v1: initial patch
v2: use separate devicetree binding
v3: change text according to feedback, rebase onto 5.0-rc3
v4: rebase onto 5.0-rc4

Documentation/devicetree/bindings/net/dsa/mt7530.txt +5 -1
index aa3527f71fdc..47aa205ee0bd 100644
@@ -3,12 +3,16 @@ Mediatek MT7530 Ethernet switch
 
 Required properties:
 
-- compatible: Must be compatible = "mediatek,mt7530";
+- compatible: may be compatible = "mediatek,mt7530"
+	or compatible = "mediatek,mt7621"
 - #address-cells: Must be 1.
 - #size-cells: Must be 0.
 - mediatek,mcm: Boolean; if defined, indicates that either MT7530 is the part
 	on multi-chip module belong to MT7623A has or the remotely standalone
 	chip as the function MT7623N reference board provided for.
+
+If compatible mediatek,mt7530 is set then the following properties are required
+
 - core-supply: Phandle to the regulator node necessary for the core power.
 - io-supply: Phandle to the regulator node necessary for the I/O power.
 	See Documentation/devicetree/bindings/regulator/mt6323-regulator.txt
Signature · 1 line
2.17.1
Reviewed-by on v4 2/3
#5 lore raw

Re: [PATCHv4 2/3] net: dsa: mt7530: support the 7530 switch on the Mediatek MT7621 SoC

In reply to [email protected]
Quoted 11 lines · On 1/29/19 5:24 PM, [email protected] wrote:

From: Greg Ungerer <[email protected]>

The MediaTek MT7621 SoC device contains a 7530 switch, and the existing linux kernel 7530 DSA switch driver can be used with it.

The bulk of the changes required stem from the 7621 having different regulator and pad setup. The existing setup of these in the 7530 driver appears to be very specific to its implemtation in the Mediatek 7623 SoC. (Not entirely surprising given the 7623 is a quad core ARM based SoC, and the 7621 is a dual core, dual thread MIPS based SoC).

Quoted 7 lines

Create a new devicetree type, "mediatek,mt7621", to support the 7530 switch in the 7621 SoC. There appears to be no usable ID register to distinguish it from a 7530 in other hardware at runtime. This is used to carry out the appropriate configuration and setup.

Signature · 1 line
Florian
Reviewed-by on v4 3/3
#8 lore raw

Re: [PATCHv4 3/3] dt-bindings: net: dsa: add new MT7530 binding to support MT7621

In reply to [email protected]
Quoted 7 lines · On 1/29/19 5:24 PM, [email protected] wrote:

From: Greg Ungerer <[email protected]>

Add devicetree binding to support the compatible mt7530 switch as used in the MediaTek MT7621 SoC.

Signature · 1 line
Florian
Reviewed-by on v4 1/3
#2 lore raw

Re: [PATCHv4 1/3] net: ethernet: mediatek: support MT7621 SoC ethernet hardware

In reply to [email protected]
Quoted 12 lines · On 1/29/19 5:24 PM, [email protected] wrote:

From: Bjørn Mork <[email protected]>

The Mediatek MT7621 SoC contains the same ethernet hardware module as used on a number of other MediaTek SoC parts. There are some minor differences to deal with but we can use the same driver to support them all.

This patch is based on work by Bjørn Mork <[email protected]>, and his original patch is at:

https://github.com/bmork/LEDE/commit/3293bc63f5461ca1eb0bbc4ed90145335e7e3404

Quoted 7 lines

There is an additional compatible devicetree type added, and the primary change to the code required is to support a single interrupt (for both RX and TX interrupts).

[[email protected]: rebase to mainline and irq handler fix]
Quoted 15 lines
---
 drivers/net/ethernet/mediatek/Kconfig       |  2 +-
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 48 ++++++++++++++++++---
 drivers/net/ethernet/mediatek/mtk_eth_soc.h |  4 ++
 3 files changed, 46 insertions(+), 8 deletions(-)

v2: first in series for this change
v3: rebase onto 5.0-rc3
v4: rebase onto 5.0-rc4

drivers/net/ethernet/mediatek/Kconfig +0 -0
index f9149d2a4694..43656f961891 100644

drivers/net/ethernet/mediatek/Kconfig line 3

Quoted 4 lines
drivers/net/ethernet/mediatek/Kconfig +1 -1
@@ -1,6 +1,6 @@
 config NET_VENDOR_MEDIATEK
 	bool "MediaTek ethernet driver"
-	depends on ARCH_MEDIATEK
+	depends on ARCH_MEDIATEK || SOC_MT7621

Would be nice to add COMPILE_TEST there as well at some point so someone can easily build test changes to the driver.

Signature · 1 line
Florian
Acked-by
#3 lore raw

Re: [PATCHv4 1/3] net: ethernet: mediatek: support MT7621 SoC ethernet hardware

Quoted 20 lines · Florian Fainelli
Quoted 16 lines · On 1/29/19 5:24 PM, [email protected] wrote:

From: Bjørn Mork <[email protected]>

The Mediatek MT7621 SoC contains the same ethernet hardware module as used on a number of other MediaTek SoC parts. There are some minor differences to deal with but we can use the same driver to support them all.

This patch is based on work by Bjørn Mork <[email protected]>, and his original patch is at:

https://github.com/bmork/LEDE/commit/3293bc63f5461ca1eb0bbc4ed90145335e7e3404

There is an additional compatible devicetree type added, and the primary change to the code required is to support a single interrupt (for both RX and TX interrupts).

Quoted 6 lines
Quoted 3 lines
[[email protected]: rebase to mainline and irq handler fix]
Quoted 10 lines
Quoted 10 lines
---
 drivers/net/ethernet/mediatek/Kconfig       |  2 +-
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 48 ++++++++++++++++++---
 drivers/net/ethernet/mediatek/mtk_eth_soc.h |  4 ++
 3 files changed, 46 insertions(+), 8 deletions(-)

v2: first in series for this change
v3: rebase onto 5.0-rc3
v4: rebase onto 5.0-rc4

Quoted 12 lines

drivers/net/ethernet/mediatek/Kconfig line 3

Quoted 9 lines
drivers/net/ethernet/mediatek/Kconfig +1 -1
index f9149d2a4694..43656f961891 100644
@@ -1,6 +1,6 @@
 config NET_VENDOR_MEDIATEK
      bool "MediaTek ethernet driver"
-     depends on ARCH_MEDIATEK
+     depends on ARCH_MEDIATEK || SOC_MT7621

Would be nice to add COMPILE_TEST there as well at some point so someone can easily build test changes to the driver.

okay, I will do it in another patch

Quoted 8 lines

--
Florian

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

Acked-by
#9 lore raw

Re: [PATCHv4 3/3] dt-bindings: net: dsa: add new MT7530 binding to support MT7621

In reply to Florian Fainelli
Quoted 6 lines · Florian Fainelli
Quoted 2 lines · On 1/29/19 5:24 PM, [email protected] wrote:

From: Greg Ungerer <[email protected]>

Quoted 7 lines
Quoted 5 lines

Add devicetree binding to support the compatible mt7530 switch as used in the MediaTek MT7621 SoC.

Quoted 7 lines

--
Florian

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

Acked-by
#6 lore raw

Re: [PATCHv4 2/3] net: dsa: mt7530: support the 7530 switch on the Mediatek MT7621 SoC

In reply to Florian Fainelli
Quoted 20 lines · Florian Fainelli
Quoted 16 lines · On 1/29/19 5:24 PM, [email protected] wrote:

From: Greg Ungerer <[email protected]>

The MediaTek MT7621 SoC device contains a 7530 switch, and the existing linux kernel 7530 DSA switch driver can be used with it.

The bulk of the changes required stem from the 7621 having different regulator and pad setup. The existing setup of these in the 7530 driver appears to be very specific to its implemtation in the Mediatek 7623 SoC. (Not entirely surprising given the 7623 is a quad core ARM based SoC, and the 7621 is a dual core, dual thread MIPS based SoC).

Create a new devicetree type, "mediatek,mt7621", to support the 7530 switch in the 7621 SoC. There appears to be no usable ID register to distinguish it from a 7530 in other hardware at runtime. This is used to carry out the appropriate configuration and setup.

Quoted 4 lines
Quoted 2 lines
Quoted 7 lines

--
Florian

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

maintainer
#10 lore raw
In reply to [email protected]

From: [email protected]
Date: Wed, 30 Jan 2019 11:24:03 +1000

Quoted 4 lines

This is the fourth version of a patch series supporting the MT7530 switch as used in the MediaTek MT7621 SoC. Unlike the MediaTek MT7623 the MT7621 is built around a dual core MIPS CPU architecture. But inside it uses basically the same 7530 switch.

...

Series applied, and yes a COMPILE_TEST Kconfig dep would be great.