Skip to contentSkip to conversation

riscv: sifive: fu540: Make GEM 10/100 Mbps work

PATCH Superseded Bin Meng 2 participants 11 messages May 16, 2019 – May 22, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

cover riscv: sifive: fu540: Make GEM 10/100 Mbps work

At present the GEM ethernet on SiFive Unleashed board can only work in 1000 Mbps mode. With a 10/100 Mbps connection it just fails to do any network communication.

This adds a new GEMGXL clock driver to adjust the clock settings per the connection speed so that 10/100 Mbps works.

Bin Meng (4):
clk: sifive: Add clock driver for GEMGXL MGMT
dm: net: macb: Update macb_linkspd_cb() signature
dm: net: macb: Implement link speed change callback
sifive: fu540: Enable GEMGXL MGMT driver

 board/sifive/fu540/Kconfig       |  1 +
 drivers/clk/sifive/Kconfig       |  7 +++++
 drivers/clk/sifive/Makefile      |  2 ++
 drivers/clk/sifive/gemgxl-mgmt.c | 60 ++++++++++++++++++++++++++++++++++++++++
 drivers/net/macb.c               | 48 +++++++++++++++++++++++++++++++-
 5 files changed, 117 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/sifive/gemgxl-mgmt.c
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/4 clk: sifive: Add clock driver for GEMGXL MGMT

This adds a clock driver to support the GEMGXL management IP block found in FU540 SoCs to control GEM TX clock operation mode for 10/100/1000 Mbps.

---

 drivers/clk/sifive/Kconfig       |  7 +++++
 drivers/clk/sifive/Makefile      |  2 ++
 drivers/clk/sifive/gemgxl-mgmt.c | 60 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+)
 create mode 100644 drivers/clk/sifive/gemgxl-mgmt.c
drivers/clk/sifive/Kconfig +7 -0
index 81fc9f8..644881b 100644
@@ -17,3 +17,10 @@ config CLK_SIFIVE_FU540_PRCI
 	  Supports the Power Reset Clock interface (PRCI) IP block found in
 	  FU540 SoCs.  If this kernel is meant to run on a SiFive FU540 SoC,
 	  enable this driver.
+
+config CLK_SIFIVE_GEMGXL_MGMT
+	bool "GEMGXL management for SiFive FU540 SoCs"
+	depends on CLK_SIFIVE
+	help
+	  Supports the GEMGXL management IP block found in FU540 SoCs to
+	  control GEM TX clock operation mode for 10/100/1000 Mbps.
drivers/clk/sifive/Makefile +2 -0
index 1155e07..f8263e7 100644
@@ -3,3 +3,5 @@
 obj-$(CONFIG_CLK_ANALOGBITS_WRPLL_CLN28HPC)	+= wrpll-cln28hpc.o
 
 obj-$(CONFIG_CLK_SIFIVE_FU540_PRCI)		+= fu540-prci.o
+
+obj-$(CONFIG_CLK_SIFIVE_GEMGXL_MGMT)		+= gemgxl-mgmt.o
drivers/clk/sifive/gemgxl-mgmt.c new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH 1/4 clk: sifive: Add clock driver for GEMGXL MGMT

Hi Bin,

Quoted 88 lines · Bin Meng

This adds a clock driver to support the GEMGXL management IP block found in FU540 SoCs to control GEM TX clock operation mode for 10/100/1000 Mbps.

---

 drivers/clk/sifive/Kconfig       |  7 +++++
 drivers/clk/sifive/Makefile      |  2 ++
 drivers/clk/sifive/gemgxl-mgmt.c | 60 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+)
 create mode 100644 drivers/clk/sifive/gemgxl-mgmt.c
drivers/clk/sifive/Kconfig +7 -0
index 81fc9f8..644881b 100644
@@ -17,3 +17,10 @@ config CLK_SIFIVE_FU540_PRCI
 	  Supports the Power Reset Clock interface (PRCI) IP block found in
 	  FU540 SoCs.  If this kernel is meant to run on a SiFive FU540 SoC,
 	  enable this driver.
+
+config CLK_SIFIVE_GEMGXL_MGMT
+	bool "GEMGXL management for SiFive FU540 SoCs"
+	depends on CLK_SIFIVE
+	help
+	  Supports the GEMGXL management IP block found in FU540 SoCs to
+	  control GEM TX clock operation mode for 10/100/1000 Mbps.
drivers/clk/sifive/Makefile +2 -0
index 1155e07..f8263e7 100644
@@ -3,3 +3,5 @@
 obj-$(CONFIG_CLK_ANALOGBITS_WRPLL_CLN28HPC)	+= wrpll-cln28hpc.o
 
 obj-$(CONFIG_CLK_SIFIVE_FU540_PRCI)		+= fu540-prci.o
+
+obj-$(CONFIG_CLK_SIFIVE_GEMGXL_MGMT)		+= gemgxl-mgmt.o
drivers/clk/sifive/gemgxl-mgmt.c new file +44 -0
new file mode 100644
index 0000000..d989989
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019, Bin Meng <[email protected]>
+ */
+
+#include <common.h>
+#include <clk-uclass.h>
+#include <dm.h>
+#include <asm/io.h>
+
+struct gemgxl_mgmt_regs {
+	__u32 tx_clk_sel;
+};
+
+struct gemgxl_mgmt_platdata {
+	struct gemgxl_mgmt_regs *regs;
+};
+
+static int gemgxl_mgmt_ofdata_to_platdata(struct udevice *dev)
+{
+	struct gemgxl_mgmt_platdata *plat = dev_get_platdata(dev);
+
+	plat->regs = (struct gemgxl_mgmt_regs *)dev_read_addr(dev);
+
+	return 0;
+}
+
+static ulong gemgxl_mgmt_set_rate(struct clk *clk, ulong rate)
+{
+	struct gemgxl_mgmt_platdata *plat = dev_get_platdata(clk->dev);
+
+	/*
+	 * GEMGXL TX clock operation mode:
+	 *
+	 * 0 = GMII mode. Use 125 MHz gemgxlclk from PRCI in TX logic
+	 *     and output clock on GMII output signal GTX_CLK
+	 * 1 = MII mode. Use MII input signal TX_CLK in TX logic
+	 */
+	writel(rate != 125000000, &plat->regs->tx_clk_sel);
+
+	return 0;
+}
+
+const struct clk_ops gemgxl_mgmt_ops = {

drivers/clk/sifive/gemgxl-mgmt.c line 54

Quoted 10 lines
drivers/clk/sifive/gemgxl-mgmt.c new file +10 -0
+	.set_rate = gemgxl_mgmt_set_rate,
+};
+
+static const struct udevice_id gemgxl_mgmt_match[] = {
+	{ .compatible = "sifive,cadencegemgxlmgmt0", },
+	{ /* sentinel */ }
+};
+
+U_BOOT_DRIVER(gemgxl_mgmt) = {
+	.name = "gemgxl-mgmt",

nit: should the driver maybe be named sifive-gemgxl-mgmt to indicate that it is a SiFive-specific driver?

Looks good otherwise!

Thanks,
Lukas

Quoted 6 lines
drivers/clk/sifive/gemgxl-mgmt.c new file +6 -0
+	.id = UCLASS_CLK,
+	.of_match = gemgxl_mgmt_match,
+	.ofdata_to_platdata = gemgxl_mgmt_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct gemgxl_mgmt_platdata),
+	.ops = &gemgxl_mgmt_ops,
+};
author
#3 lore raw

PATCH 1/4 clk: sifive: Add clock driver for GEMGXL MGMT

Hi Lukas,

Quoted 97 lines · Lukas

Hi Bin,

Quoted 93 lines · Bin Meng

This adds a clock driver to support the GEMGXL management IP block found in FU540 SoCs to control GEM TX clock operation mode for 10/100/1000 Mbps.

---

 drivers/clk/sifive/Kconfig       |  7 +++++
 drivers/clk/sifive/Makefile      |  2 ++
 drivers/clk/sifive/gemgxl-mgmt.c | 60 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+)
 create mode 100644 drivers/clk/sifive/gemgxl-mgmt.c
drivers/clk/sifive/Kconfig +7 -0
index 81fc9f8..644881b 100644
@@ -17,3 +17,10 @@ config CLK_SIFIVE_FU540_PRCI
        Supports the Power Reset Clock interface (PRCI) IP block found in
        FU540 SoCs.  If this kernel is meant to run on a SiFive FU540 SoC,
        enable this driver.
+
+config CLK_SIFIVE_GEMGXL_MGMT
+     bool "GEMGXL management for SiFive FU540 SoCs"
+     depends on CLK_SIFIVE
+     help
+       Supports the GEMGXL management IP block found in FU540 SoCs to
+       control GEM TX clock operation mode for 10/100/1000 Mbps.
drivers/clk/sifive/Makefile +2 -0
index 1155e07..f8263e7 100644
@@ -3,3 +3,5 @@
 obj-$(CONFIG_CLK_ANALOGBITS_WRPLL_CLN28HPC)  += wrpll-cln28hpc.o
 
 obj-$(CONFIG_CLK_SIFIVE_FU540_PRCI)          += fu540-prci.o
+
+obj-$(CONFIG_CLK_SIFIVE_GEMGXL_MGMT)         += gemgxl-mgmt.o
drivers/clk/sifive/gemgxl-mgmt.c new file +49 -0
new file mode 100644
index 0000000..d989989
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019, Bin Meng <[email protected]>
+ */
+
+#include <common.h>
+#include <clk-uclass.h>
+#include <dm.h>
+#include <asm/io.h>
+
+struct gemgxl_mgmt_regs {
+     __u32 tx_clk_sel;
+};
+
+struct gemgxl_mgmt_platdata {
+     struct gemgxl_mgmt_regs *regs;
+};
+
+static int gemgxl_mgmt_ofdata_to_platdata(struct udevice *dev)
+{
+     struct gemgxl_mgmt_platdata *plat = dev_get_platdata(dev);
+
+     plat->regs = (struct gemgxl_mgmt_regs *)dev_read_addr(dev);
+
+     return 0;
+}
+
+static ulong gemgxl_mgmt_set_rate(struct clk *clk, ulong rate)
+{
+     struct gemgxl_mgmt_platdata *plat = dev_get_platdata(clk->dev);
+
+     /*
+      * GEMGXL TX clock operation mode:
+      *
+      * 0 = GMII mode. Use 125 MHz gemgxlclk from PRCI in TX logic
+      *     and output clock on GMII output signal GTX_CLK
+      * 1 = MII mode. Use MII input signal TX_CLK in TX logic
+      */
+     writel(rate != 125000000, &plat->regs->tx_clk_sel);
+
+     return 0;
+}
+
+const struct clk_ops gemgxl_mgmt_ops = {
+     .set_rate = gemgxl_mgmt_set_rate,
+};
+
+static const struct udevice_id gemgxl_mgmt_match[] = {
+     { .compatible = "sifive,cadencegemgxlmgmt0", },
Quoted 8 lines

drivers/clk/sifive/gemgxl-mgmt.c line 54

Quoted 5 lines
drivers/clk/sifive/gemgxl-mgmt.c new file +5 -0
+     { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(gemgxl_mgmt) = {
+     .name = "gemgxl-mgmt",

nit: should the driver maybe be named sifive-gemgxl-mgmt to indicate that it is a SiFive-specific driver?

Will rename the driver in v2.

Quoted 6 lines

Looks good otherwise!

Regards,
Bin

author
#4 lore raw

PATCH 2/4 dm: net: macb: Update macb_linkspd_cb() signature

In reply to Bin Meng

This updates DM version macb_linkspd_cb() signature for future expansion, eg: adding an implementation for link speed changes.

---

 drivers/net/macb.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/net/macb.c +21 -1
index 7261416..b7f404e 100644
@@ -488,15 +488,23 @@ static int macb_phy_find(struct macb_device *macb, const char *name)
 
 /**
  * macb_linkspd_cb - Linkspeed change callback function
- * @regs:	Base Register of MACB devices
+ * @dev/@regs:	MACB udevice (DM version) or
+ *		Base Register of MACB devices (non-DM version)
  * @speed:	Linkspeed
  * Returns 0 when operation success and negative errno number
  * when operation failed.
  */
+#ifdef CONFIG_DM_ETH
+int __weak macb_linkspd_cb(struct udevice *dev, unsigned int speed)
+{
+	return 0;
+}
+#else
 int __weak macb_linkspd_cb(void *regs, unsigned int speed)
 {
 	return 0;
 }
+#endif
 
 #ifdef CONFIG_DM_ETH
 static int macb_phy_init(struct udevice *dev, const char *name)
@@ -589,7 +597,11 @@ static int macb_phy_init(struct macb_device *macb, const char *name)
 
 			macb_writel(macb, NCFGR, ncfgr);
 
+#ifdef CONFIG_DM_ETH
+			ret = macb_linkspd_cb(dev, _1000BASET);
+#else
 			ret = macb_linkspd_cb(macb->regs, _1000BASET);
+#endif
 			if (ret)
 				return ret;
 
@@ -614,9 +626,17 @@ static int macb_phy_init(struct macb_device *macb, const char *name)
 	ncfgr &= ~(MACB_BIT(SPD) | MACB_BIT(FD) | GEM_BIT(GBE));
 	if (speed) {
 		ncfgr |= MACB_BIT(SPD);
+#ifdef CONFIG_DM_ETH
+		ret = macb_linkspd_cb(dev, _100BASET);
+#else
 		ret = macb_linkspd_cb(macb->regs, _100BASET);
+#endif
 	} else {
+#ifdef CONFIG_DM_ETH
+		ret = macb_linkspd_cb(dev, _10BASET);
+#else
 		ret = macb_linkspd_cb(macb->regs, _10BASET);
+#endif
 	}
 
 	if (ret)
Signature · 1 line
2.7.4
#5 lore raw

PATCH 2/4 dm: net: macb: Update macb_linkspd_cb() signature

Quoted 9 lines · Bin Meng

This updates DM version macb_linkspd_cb() signature for future expansion, eg: adding an implementation for link speed changes.

---

 drivers/net/macb.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
author
#6 lore raw

PATCH 3/4 dm: net: macb: Implement link speed change callback

In reply to Bin Meng

At present the link speed change callback is a nop. According to macb device tree bindings, an optional "tx_clk" is used to clock the ethernet controller's TX_CLK under different link speed.

In 10/100 MII mode, transmit logic must be clocked from a free running clock generated by the external PHY. In gigabit GMII mode, the controller, not the external PHY, must generate the 125 MHz transmit clock towards the PHY.

---

 drivers/net/macb.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/net/macb.c +26 -0
index b7f404e..7d86fa1 100644
@@ -497,6 +497,32 @@ static int macb_phy_find(struct macb_device *macb, const char *name)
 #ifdef CONFIG_DM_ETH
 int __weak macb_linkspd_cb(struct udevice *dev, unsigned int speed)
 {
+#ifdef CONFIG_CLK
+	struct clk tx_clk;
+	ulong rate;
+	int ret;
+
+	ret = clk_get_by_name(dev, "tx_clk", &tx_clk);
+	if (ret)
+		return 0;
+
+	switch (speed) {
+	case _10BASET:
+		rate = 2500000;
+		break;
+	case _100BASET:
+		rate = 25000000;
+		break;
+	case _1000BASET:
+	default:
+		rate = 125000000;
+		break;
+	}
+
+	if (tx_clk.dev)
+		clk_set_rate(&tx_clk, rate);
+#endif
+
 	return 0;
 }
 #else
Signature · 1 line
2.7.4
#7 lore raw

PATCH 3/4 dm: net: macb: Implement link speed change callback

Hi Bin,

Quoted 21 lines · Bin Meng

At present the link speed change callback is a nop. According to macb device tree bindings, an optional "tx_clk" is used to clock the ethernet controller's TX_CLK under different link speed.

In 10/100 MII mode, transmit logic must be clocked from a free running clock generated by the external PHY. In gigabit GMII mode, the controller, not the external PHY, must generate the 125 MHz transmit clock towards the PHY.

---

 drivers/net/macb.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/net/macb.c +0 -0
index b7f404e..7d86fa1 100644
@@ -497,6 +497,32 @@ static int macb_phy_find(struct macb_device *macb, const char *name)
 #ifdef CONFIG_DM_ETH

drivers/net/macb.c static int macb_phy_find(struct macb_device *macb, const char *name) · line 507

Quoted 10 lines
drivers/net/macb.c +8 -0
 int __weak macb_linkspd_cb(struct udevice *dev, unsigned int speed)
 {
+#ifdef CONFIG_CLK
+	struct clk tx_clk;
+	ulong rate;
+	int ret;
+
+	ret = clk_get_by_name(dev, "tx_clk", &tx_clk);
+	if (ret)
+		return 0;

Can you return errors in ret here?

drivers/net/macb.c static int macb_phy_find(struct macb_device *macb, const char *name) · line 519

Quoted 12 lines
drivers/net/macb.c +12 -0
+
+	switch (speed) {
+	case _10BASET:
+		rate = 2500000;
+		break;
+	case _100BASET:
+		rate = 25000000;
+		break;
+	case _1000BASET:
+	default:
+		rate = 125000000;
+		break;

The Linux driver simply returns in the default case, without changing tx_clk. I am wondering if we should do the same in U-Boot?

drivers/net/macb.c static int macb_phy_find(struct macb_device *macb, const char *name) · line 523

Quoted 4 lines
drivers/net/macb.c +4 -0
+	}
+
+	if (tx_clk.dev)
+		clk_set_rate(&tx_clk, rate);

Can you also check the return value of clk_set_rate() here?

Thanks,
Lukas

Quoted 5 lines
drivers/net/macb.c +2 -0
+#endif
+
 	return 0;
 }
 #else
author
#8 lore raw

PATCH 3/4 dm: net: macb: Implement link speed change callback

Hi Lukas,

Quoted 29 lines · Lukas

Hi Bin,

Quoted 25 lines · Bin Meng

At present the link speed change callback is a nop. According to macb device tree bindings, an optional "tx_clk" is used to clock the ethernet controller's TX_CLK under different link speed.

In 10/100 MII mode, transmit logic must be clocked from a free running clock generated by the external PHY. In gigabit GMII mode, the controller, not the external PHY, must generate the 125 MHz transmit clock towards the PHY.

---

 drivers/net/macb.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/net/macb.c +2 -0
index b7f404e..7d86fa1 100644
@@ -497,6 +497,32 @@ static int macb_phy_find(struct macb_device *macb, const char *name)
 #ifdef CONFIG_DM_ETH
 int __weak macb_linkspd_cb(struct udevice *dev, unsigned int speed)
 {
+#ifdef CONFIG_CLK
+     struct clk tx_clk;
Quoted 8 lines

drivers/net/macb.c static int macb_phy_find(struct macb_device *macb, const char *name) · line 507

Quoted 6 lines
drivers/net/macb.c +6 -0
+     ulong rate;
+     int ret;
+
+     ret = clk_get_by_name(dev, "tx_clk", &tx_clk);
+     if (ret)
+             return 0;

Can you return errors in ret here?

No, we should ignore DT that does not contain the "tx_clk" source hence cannot return error here. I will add a comment in v2.

Quoted 14 lines

drivers/net/macb.c static int macb_phy_find(struct macb_device *macb, const char *name) · line 519

Quoted 13 lines
drivers/net/macb.c +12 -0
+
+     switch (speed) {
+     case _10BASET:
+             rate = 2500000;
+             break;
+     case _100BASET:
+             rate = 25000000;
+             break;
+     case _1000BASET:
+     default:
+             rate = 125000000;
+             break;
Quoted 2 lines

The Linux driver simply returns in the default case, without changing tx_clk. I am wondering if we should do the same in U-Boot?

Sure.

Quoted 7 lines

drivers/net/macb.c static int macb_phy_find(struct macb_device *macb, const char *name) · line 523

Quoted 5 lines
drivers/net/macb.c +4 -0
+     }
+
+     if (tx_clk.dev)
+             clk_set_rate(&tx_clk, rate);

Can you also check the return value of clk_set_rate() here?

Will add the return value check in v2.

Regards,
Bin

author
#9 lore raw

PATCH 4/4 sifive: fu540: Enable GEMGXL MGMT driver

In reply to Bin Meng

Enable the new GEMGXL MGMT driver so that GEM 10/100 Mbps works now.

---

 board/sifive/fu540/Kconfig | 1 +
 1 file changed, 1 insertion(+)
board/sifive/fu540/Kconfig +1 -0
index f464379..8eb5e30 100644
@@ -28,6 +28,7 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	imply CMD_PING
 	imply CLK_SIFIVE
 	imply CLK_SIFIVE_FU540_PRCI
+	imply CLK_SIFIVE_GEMGXL_MGMT
 	imply DOS_PARTITION
 	imply EFI_PARTITION
 	imply IP_DYN
Signature · 1 line
2.7.4
#10 lore raw

PATCH 4/4 sifive: fu540: Enable GEMGXL MGMT driver

Quoted 9 lines · Bin Meng

Enable the new GEMGXL MGMT driver so that GEM 10/100 Mbps works now.

---

 board/sifive/fu540/Kconfig | 1 +
 1 file changed, 1 insertion(+)

Thanks for the patch series. I tested it successfully on a SiFive HiFive Unleashed board at 10, 100, and 1000 Mbps link speeds. Without the patch series, ethernet at 10 and 100 Mbps link speeds did not work.