Skip to contentSkip to conversation

net: ethernet: stmmac: add missing sgmii configure for ipq806x

PATCH Superseded Christian 'Ansuel' Marangi 2 participants 4 messages Jun 9, 2022 – Jun 14, 2022

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 net: ethernet: stmmac: add missing sgmii configure for ipq806x

The different gmacid require different configuration based on the soc and on the gmac id. Add these missing configuration taken from the original driver.

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  1 +
 .../ethernet/stmicro/stmmac/dwmac-ipq806x.c   | 93 +++++++++++++++----
 2 files changed, 78 insertions(+), 16 deletions(-)
drivers/net/ethernet/stmicro/stmmac/Kconfig +1 -0
index 929cfc22cd0c..c4bca16dae57 100644
@@ -83,6 +83,7 @@ config DWMAC_IPQ806X
 	default ARCH_QCOM
 	depends on OF && (ARCH_QCOM || COMPILE_TEST)
 	select MFD_SYSCON
+	select QCOM_SOCINFO
 	help
 	  Support for QCA IPQ806X DWMAC Ethernet.
 
drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c +77 -16

117 lines not on this page · raw message

Signature · 1 line
2.36.1
#1 lore raw

PATCH 2/2 net: ethernet: stmmac: reset force speed bit for ipq806x

Some bootloader may set the force speed regs even if the actual interface should use autonegotiation between PCS and PHY. This cause the complete malfuction of the interface.

To fix this correctly reset the force speed regs if a fixed-link is not defined in the DTS. With a fixed-link node correctly configure the forced speed regs to handle any misconfiguration by the bootloader.

---
 .../ethernet/stmicro/stmmac/dwmac-ipq806x.c   | 65 +++++++++++++++++++
 1 file changed, 65 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c +65 -0
index 832f442254d8..0f2f2bc6873d 100644
@@ -66,6 +66,17 @@
 #define NSS_COMMON_CLK_DIV_SGMII_100		4
 #define NSS_COMMON_CLK_DIV_SGMII_10		49
 
+#define QSGMII_PCS_ALL_CH_CTL			0x80
+#define QSGMII_PCS_CH_SPEED_FORCE		BIT(1)
+#define QSGMII_PCS_CH_SPEED_10			0x0
+#define QSGMII_PCS_CH_SPEED_100			BIT(2)
+#define QSGMII_PCS_CH_SPEED_1000		BIT(3)
+#define QSGMII_PCS_CH_SPEED_MASK		(QSGMII_PCS_CH_SPEED_FORCE | \
+						 QSGMII_PCS_CH_SPEED_10 | \
+						 QSGMII_PCS_CH_SPEED_100 | \
+						 QSGMII_PCS_CH_SPEED_1000)
+#define QSGMII_PCS_CH_SPEED_SHIFT(x)		((x) * 4)
+
 #define QSGMII_PCS_CAL_LCKDT_CTL		0x120
 #define QSGMII_PCS_CAL_LCKDT_CTL_RST		BIT(19)
 
@@ -253,6 +264,56 @@ static void ipq806x_gmac_fix_mac_speed(void *priv, unsigned int speed)
 	ipq806x_gmac_set_speed(gmac, speed);
 }
 
+static int
+ipq806x_gmac_configure_qsgmii_pcs_speed(struct ipq806x_gmac *gmac)
+{
+	struct platform_device *pdev = gmac->pdev;
+	struct device *dev = &pdev->dev;
+	struct device_node *dn;
+	int link_speed;
+	int val = 0;
+	int ret;
+
+	/* Some bootloader may apply wrong configuration and cause
+	 * not functioning port. If fixed link is not set,
+	 * reset the force speed bit.
+	 */
+	if (!of_phy_is_fixed_link(pdev->dev.of_node))
+		goto write;
+
+	dn = of_get_child_by_name(pdev->dev.of_node, "fixed-link");
+	ret = of_property_read_u32(dn, "speed", &link_speed);
+	if (ret) {
+		dev_err(dev, "found fixed-link node with no speed");
+		return ret;
+	}
+
+	of_node_put(dn);
+
+	val = QSGMII_PCS_CH_SPEED_FORCE;
+
+	switch (link_speed) {
+	case SPEED_1000:
+		val |= QSGMII_PCS_CH_SPEED_1000;
+		break;
+	case SPEED_100:
+		val |= QSGMII_PCS_CH_SPEED_100;
+		break;
+	case SPEED_10:
+		val |= QSGMII_PCS_CH_SPEED_10;
+		break;
+	}
+
+write:
+	regmap_update_bits(gmac->qsgmii_csr, QSGMII_PCS_ALL_CH_CTL,
+			   QSGMII_PCS_CH_SPEED_MASK <<
+			   QSGMII_PCS_CH_SPEED_SHIFT(gmac->id),
+			   val <<
+			   QSGMII_PCS_CH_SPEED_SHIFT(gmac->id));
+
+	return 0;
+}
+
 static const struct soc_device_attribute ipq806x_gmac_soc_v1[] = {
 	{
 		.revision = "1.*",
@@ -400,6 +461,10 @@ static int ipq806x_gmac_probe(struct platform_device *pdev)
 		err = ipq806x_gmac_configure_qsgmii_params(gmac);
 		if (err)
 			goto err_remove_config_dt;
+
+		err = ipq806x_gmac_configure_qsgmii_pcs_speed(gmac);
+		if (err)
+			goto err_remove_config_dt;
 	}
 
 	plat_dat->has_gmac = true;
Signature · 1 line
2.36.1
maintainer
#2 lore raw

Re: [net-next PATCH 2/2] net: ethernet: stmmac: reset force speed bit for ipq806x

drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c static void ipq806x_gmac_fix_mac_speed(void *priv, unsigned int speed) · line 288

Quoted 5 lines · On Thu, 9 Jun 2022 02:28:31 +0200 Christian 'Ansuel' Marangi wrote:
drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c +5 -0
+	dn = of_get_child_by_name(pdev->dev.of_node, "fixed-link");
+	ret = of_property_read_u32(dn, "speed", &link_speed);
+	if (ret) {
+		dev_err(dev, "found fixed-link node with no speed");
+		return ret;

Doesn't this return potentially leak the reference on dn? You move the of_node_put() right before the if (ret) {

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c +3 -0
+	}
+
+	of_node_put(dn);
#3 lore raw

Re: [net-next PATCH 2/2] net: ethernet: stmmac: reset force speed bit for ipq806x

Quoted 10 lines · Jakub Kicinski

drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c static void ipq806x_gmac_fix_mac_speed(void *priv, unsigned int speed) · line 288

Quoted 5 lines · On Thu, 9 Jun 2022 02:28:31 +0200 Christian 'Ansuel' Marangi wrote:
drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c +5 -0
+	dn = of_get_child_by_name(pdev->dev.of_node, "fixed-link");
+	ret = of_property_read_u32(dn, "speed", &link_speed);
+	if (ret) {
+		dev_err(dev, "found fixed-link node with no speed");
+		return ret;

Doesn't this return potentially leak the reference on dn? You move the of_node_put() right before the if (ret) {

Totally right. Will fix in v2.

Quoted 3 lines
Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c +3 -0
+	}
+
+	of_node_put(dn);
Signature · 1 line
	Ansuel