Skip to contentSkip to conversation

Add StarFive JHB100 soc SGMII GMAC support

PATCH Superseded Minda Chen 2 participants 13 messages Apr 8 – Apr 9

Subsystems (6)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Minda Chen

author maintainer
#0 lore raw

cover Add StarFive JHB100 soc SGMII GMAC support

JHB100 is a Starfive new RISC-V SoC for datacenter BMC (BaseBoard Managent Controller). Similar with Aspeed 27x0.

The JHB100 minimal system upstream is in progress:
https://patchwork.kernel.org/project/linux-riscv/cover/[email protected]/

JHB100 GMAC still using designware GMAC core like JH7100 and JH7110, and contains 2 SGMII interfaces, 1 RGMII/RMII interface, 1 RMII interface. In JH7100/JH7110 dwmac-starfive.c have supported RGMII/RMII interface. So require to add SGMII support to dwmac-starfive.c for JHB100.

SGMII serdes PHY has been intergrated in JHB100 and do not have driver setting.

In JHB100 EVB board, SGMII connect with motorcomm YT8531s external PHY and support RJ45 ethernet port.

The patch base in 7.0-rc5

Minda Chen (5):
dt-bindings: net: starfive,jh7110-dwmac: Remove JH8100
dt-bindings: net: starfive,jh7110-dwmac: Add JHB100 support
dt-bindings: net: starfive,jh7110-dwmac: Add JHB100 sgmii rx clk
net: stmmac: starfive: Add JHB100 SGMII interface
net: stmmac: starfive: Add STMMAC_FLAG_SPH_DISABLE flag

 .../devicetree/bindings/net/snps,dwmac.yaml   |  1 +
 .../bindings/net/starfive,jh7110-dwmac.yaml   | 89 +++++++++++++------
 .../ethernet/stmicro/stmmac/dwmac-starfive.c  | 38 +++++++-
 3 files changed, 98 insertions(+), 30 deletions(-)

base-commit: c369299895a591d96745d6492d4888259b004a9e

Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH 1/5 dt-bindings: net: starfive,jh7110-dwmac: Remove JH8100

Remove JH8100 dt-bindings because do not support it now.

---
 .../bindings/net/starfive,jh7110-dwmac.yaml   | 28 ++++---------------
 1 file changed, 5 insertions(+), 23 deletions(-)
Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml +5 -23
index 313a15331661..0d1962980f57 100644
@@ -30,10 +30,6 @@ properties:
       - items:
           - const: starfive,jh7110-dwmac
           - const: snps,dwmac-5.20
-      - items:
-          - const: starfive,jh8100-dwmac
-          - const: starfive,jh7110-dwmac
-          - const: snps,dwmac-5.20
 
   reg:
     maxItems: 1
@@ -120,25 +116,11 @@ allOf:
           minItems: 3
           maxItems: 3
 
-      if:
-        properties:
-          compatible:
-            contains:
-              const: starfive,jh8100-dwmac
-      then:
-        properties:
-          resets:
-            maxItems: 1
-
-          reset-names:
-            const: stmmaceth
-      else:
-        properties:
-          resets:
-            minItems: 2
-
-          reset-names:
-            minItems: 2
+        resets:
+          minItems: 2
+
+        reset-names:
+          minItems: 2
 
 unevaluatedProperties: false
 
Signature · 1 line
2.17.1
#2 lore raw

Re: [net-next v1 v1 1/5] dt-bindings: net: starfive,jh7110-dwmac: Remove JH8100

Quoted 1 line · Minda Chen

Remove JH8100 dt-bindings because do not support it now.

Could you expand on that. If there are devices out in the field, we don't just drop support for it because the vendor has something newer.

If the device never made it outside of the vendors lab, then we might consider dropping it.

Please explain in detail why this is being dropped.

Andrew

author maintainer
#3 lore raw

Re: [net-next v1 v1 1/5] dt-bindings: net: starfive,jh7110-dwmac: Remove JH8100

Quoted 9 lines · Minda Chen
Quoted 1 line

Remove JH8100 dt-bindings because do not support it now.

Could you expand on that. If there are devices out in the field, we don't just drop support for it because the vendor has something newer.

Quoted 6 lines

If the device never made it outside of the vendors lab, then we might consider dropping it.

Please explain in detail why this is being dropped.

Andrew

Yes.
We (StarFive) stop developing on JH8100 now, And do NOT release the SoC outside.

Hi Krzysztof
Could you review this series patch 1 -3 which is dt -binding doc changes? I sorry
I have sent you to old e-mail address.

#4 lore raw

Re: [net-next v1 v1 1/5] dt-bindings: net: starfive,jh7110-dwmac: Remove JH8100

Quoted 2 lines

Yes.
We (StarFive) stop developing on JH8100 now, And do NOT release the SoC outside.

Please add that to the commit message as the justification of removing support.

Andrew

author maintainer
#5 lore raw

PATCH 2/5 dt-bindings: net: starfive,jh7110-dwmac: Add JHB100 support

In reply to Minda Chen

Add StarFive JHB100 dwmac support and compatible.
The JHB100 dwmac shares the same driver code as the JH7110 dwmac, which contains 2 SGMII interfaces, 1 RGMII/RMII interface and 1 RMII interface.
JHB100 dwmacc has only one reset signal and one main interrupt line.

Please refer to below:

JHB100: reset-names = "stmmaceth";

Example usage of JHB100 in the device tree:

gmac0: ethernet@11b80000 {
        compatible = "starfive,jhb100-dwmac",
                     "snps,dwmac-5.20";
        interrupts = <225>;
        interrupt-names = "macirq";
        ...
};
---
 .../devicetree/bindings/net/snps,dwmac.yaml   |  1 +
 .../bindings/net/starfive,jh7110-dwmac.yaml   | 23 +++++++++++++++++++
 2 files changed, 24 insertions(+)
Documentation/devicetree/bindings/net/snps,dwmac.yaml +1 -0
index 38bc34dc4f09..85cd3252e8b1 100644
@@ -115,6 +115,7 @@ properties:
         - sophgo,sg2044-dwmac
         - starfive,jh7100-dwmac
         - starfive,jh7110-dwmac
+        - starfive,jhb100-dwmac
         - tesla,fsd-ethqos
         - thead,th1520-gmac
 
Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml +23 -0
index 0d1962980f57..edc246a71ce3 100644
@@ -18,6 +18,7 @@ select:
         enum:
           - starfive,jh7100-dwmac
           - starfive,jh7110-dwmac
+          - starfive,jhb100-dwmac
   required:
     - compatible
 
@@ -30,6 +31,9 @@ properties:
       - items:
           - const: starfive,jh7110-dwmac
           - const: snps,dwmac-5.20
+      - items:
+          - const: starfive,jhb100-dwmac
+          - const: snps,dwmac-5.20
 
   reg:
     maxItems: 1
@@ -122,6 +126,25 @@ allOf:
         reset-names:
           minItems: 2
 
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: starfive,jhb100-dwmac
+    then:
+      properties:
+        interrupts:
+          maxItems: 1
+
+        interrupt-names:
+          const: macirq
+
+        resets:
+          maxItems: 1
+
+        reset-names:
+          const: stmmaceth
+
 unevaluatedProperties: false
 
 examples:
Signature · 1 line
2.17.1
author maintainer
#6 lore raw

PATCH 3/5 dt-bindings: net: starfive,jh7110-dwmac: Add JHB100 sgmii rx clk

In reply to Minda Chen

JHB100 SGMII interface tx/rx mac clock is split and require to set clock rate in 10M/100M/1000M speed. So dts need to add a new rx clock in code, dts and dt binding doc.

---
 .../bindings/net/starfive,jh7110-dwmac.yaml   | 42 ++++++++++++++++---
 1 file changed, 36 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml +36 -6
index edc246a71ce3..847d67a2c1d5 100644
@@ -39,20 +39,26 @@ properties:
     maxItems: 1
 
   clocks:
+    minItems: 5
     items:
       - description: GMAC main clock
       - description: GMAC AHB clock
       - description: PTP clock
       - description: TX clock
       - description: GTX clock
+      - description: SGMII RX clock
 
   clock-names:
-    items:
-      - const: stmmaceth
-      - const: pclk
-      - const: ptp_ref
-      - const: tx
-      - const: gtx
+    minItems: 5
+    maxItems: 6
+    contains:
+      enum:
+       - stmmaceth
+       - pclk
+       - ptp_ref
+       - tx
+       - gtx
+       - rx
 
   starfive,tx-use-rgmii-clk:
     description:
@@ -99,6 +105,14 @@ allOf:
           minItems: 2
           maxItems: 2
 
+        clocks:
+          minItems: 5
+          maxItems: 5
+
+        clock-names:
+          minItems: 5
+          maxItems: 5
+
         resets:
           maxItems: 1
 
@@ -120,6 +134,14 @@ allOf:
           minItems: 3
           maxItems: 3
 
+        clocks:
+          minItems: 5
+          maxItems: 5
+
+        clock-names:
+          minItems: 5
+          maxItems: 5
+
         resets:
           minItems: 2
 
@@ -139,6 +161,14 @@ allOf:
         interrupt-names:
           const: macirq
 
+        clocks:
+          minItems: 5
+          maxItems: 6
+
+        clock-names:
+          minItems: 5
+          maxItems: 6
+
         resets:
           maxItems: 1
 
Signature · 1 line
2.17.1
#7 lore raw

Re: [net-next v1 v1 3/5] dt-bindings: net: starfive,jh7110-dwmac: Add JHB100 sgmii rx clk

Quoted 9 lines
Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml +1 -6
+      - description: SGMII RX clock
 
   clock-names:
-    items:
-      - const: stmmaceth
-      - const: pclk
-      - const: ptp_ref
-      - const: tx
-      - const: gtx

Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml properties: · line 61

Quoted 10 lines
Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml +10 -0
+    minItems: 5
+    maxItems: 6
+    contains:
+      enum:
+       - stmmaceth
+       - pclk
+       - ptp_ref
+       - tx
+       - gtx
+       - rx

If this is only used for sgmii, maybe it should have sgmii in the name?

Andrew

author maintainer
#8 lore raw

回复: [net-next v1 v1 3/5] dt-bindings: net: starfive,jh7110-dwmac: Add JHB100 sgmii rx clk

Quoted 23 lines
Quoted 12 lines
Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml +1 -6
+      - description: SGMII RX clock
 
   clock-names:
-    items:
-      - const: stmmaceth
-      - const: pclk
-      - const: ptp_ref
-      - const: tx
-      - const: gtx

Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml properties: · line 61

Quoted 10 lines
Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml +10 -0
+    minItems: 5
+    maxItems: 6
+    contains:
+      enum:
+       - stmmaceth
+       - pclk
+       - ptp_ref
+       - tx
+       - gtx
+       - rx
Quoted 3 lines

If this is only used for sgmii, maybe it should have sgmii in the name?

Andrew

Okay. I will change to "sgmii_rx". Thanks

author maintainer
#9 lore raw

PATCH 4/5 net: stmmac: starfive: Add JHB100 SGMII interface

In reply to Minda Chen

Add JHB100 compatible and SGMII support. JHB100 soc contains 2 SGMII interfaces and integrated with serdes PHY. SGMII with split TX/RX MAC clock and need to set 2.5M/25M/125M TX/RX clock rate in 10M/100M/1000M speed mode.

---
 .../ethernet/stmicro/stmmac/dwmac-starfive.c  | 36 +++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c +34 -2
index 16b955a6d77b..df7b2fc9989d 100644
@@ -26,6 +26,7 @@ struct starfive_dwmac_data {
 struct starfive_dwmac {
 	struct device *dev;
 	const struct starfive_dwmac_data *data;
+	struct clk *sgmii_rx;
 };
 
 static int starfive_dwmac_set_mode(struct plat_stmmacenet_data *plat_dat)
@@ -36,6 +37,9 @@ static int starfive_dwmac_set_mode(struct plat_stmmacenet_data *plat_dat)
 	int phy_intf_sel;
 	int err;
 
+	if (plat_dat->phy_interface == PHY_INTERFACE_MODE_SGMII)
+		return 0;
+
 	phy_intf_sel = stmmac_get_phy_intf_sel(plat_dat->phy_interface);
 	if (phy_intf_sel != PHY_INTF_SEL_RGMII &&
 	    phy_intf_sel != PHY_INTF_SEL_RMII) {
@@ -68,6 +72,24 @@ static int starfive_dwmac_set_mode(struct plat_stmmacenet_data *plat_dat)
 	return 0;
 }
 
+static int stmmac_starfive_sgmii_set_clk_rate(void *bsp_priv, struct clk *clk_tx_i,
+					      phy_interface_t interface, int speed)
+{
+	struct starfive_dwmac *dwmac = (void *)bsp_priv;
+	long rate = rgmii_clock(speed);
+	int ret;
+
+	/* MAC clock rate the same as RGMII */
+	if (rate < 0)
+		return 0;
+
+	ret = clk_set_rate(clk_tx_i, rate);
+	if (ret)
+		return ret;
+
+	return clk_set_rate(dwmac->sgmii_rx, rate);
+}
+
 static int starfive_dwmac_probe(struct platform_device *pdev)
 {
 	struct plat_stmmacenet_data *plat_dat;
@@ -102,14 +124,23 @@ static int starfive_dwmac_probe(struct platform_device *pdev)
 		return dev_err_probe(&pdev->dev, PTR_ERR(clk_gtx),
 				     "error getting gtx clock\n");
 
+	dwmac->sgmii_rx = devm_clk_get_optional(&pdev->dev, "rx");
+	if (IS_ERR(dwmac->sgmii_rx))
+		return dev_err_probe(&pdev->dev, PTR_ERR(dwmac->sgmii_rx),
+				     "error getting sgmii rx clock\n");
+
 	/* Generally, the rgmii_tx clock is provided by the internal clock,
 	 * which needs to match the corresponding clock frequency according
 	 * to different speeds. If the rgmii_tx clock is provided by the
 	 * external rgmii_rxin, there is no need to configure the clock
 	 * internally, because rgmii_rxin will be adaptively adjusted.
 	 */
-	if (!device_property_read_bool(&pdev->dev, "starfive,tx-use-rgmii-clk"))
-		plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate;
+	if (!device_property_read_bool(&pdev->dev, "starfive,tx-use-rgmii-clk")) {
+		if (plat_dat->phy_interface == PHY_INTERFACE_MODE_SGMII)
+			plat_dat->set_clk_tx_rate = stmmac_starfive_sgmii_set_clk_rate;
+		else
+			plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate;
+	}
 
 	dwmac->dev = &pdev->dev;
 	plat_dat->flags |= STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP;
@@ -130,6 +161,7 @@ static const struct starfive_dwmac_data jh7100_data = {
 static const struct of_device_id starfive_dwmac_match[] = {
 	{ .compatible = "starfive,jh7100-dwmac", .data = &jh7100_data },
 	{ .compatible = "starfive,jh7110-dwmac" },
+	{ .compatible = "starfive,jhb100-dwmac" },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, starfive_dwmac_match);
Signature · 1 line
2.17.1
#10 lore raw

Re: [net-next v1 v1 4/5] net: stmmac: starfive: Add JHB100 SGMII interface

drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c static int starfive_dwmac_probe(struct platform_device *pdev) · line 131

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c +5 -0
+	dwmac->sgmii_rx = devm_clk_get_optional(&pdev->dev, "rx");
+	if (IS_ERR(dwmac->sgmii_rx))
+		return dev_err_probe(&pdev->dev, PTR_ERR(dwmac->sgmii_rx),
+				     "error getting sgmii rx clock\n");
+

The SGMII clock is optional...

drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c static int starfive_dwmac_probe(struct platform_device *pdev) · line 140

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c +3 -2
 	/* Generally, the rgmii_tx clock is provided by the internal clock,
 	 * which needs to match the corresponding clock frequency according
 	 * to different speeds. If the rgmii_tx clock is provided by the
 	 * external rgmii_rxin, there is no need to configure the clock
 	 * internally, because rgmii_rxin will be adaptively adjusted.
 	 */
-	if (!device_property_read_bool(&pdev->dev, "starfive,tx-use-rgmii-clk"))
-		plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate;
+	if (!device_property_read_bool(&pdev->dev, "starfive,tx-use-rgmii-clk")) {
+		if (plat_dat->phy_interface == PHY_INTERFACE_MODE_SGMII)
+			plat_dat->set_clk_tx_rate = stmmac_starfive_sgmii_set_clk_rate;

So you probably want to return an error here if it is missing.

Or you might want to look at the compatible, and make the clock mandatory for this device.

Andrew

author maintainer
#11 lore raw

Re: [net-next v1 v1 4/5] net: stmmac: starfive: Add JHB100 SGMII interface

Quoted 11 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c static int starfive_dwmac_probe(struct platform_device *pdev) · line 131

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c +5 -0
+	dwmac->sgmii_rx = devm_clk_get_optional(&pdev->dev, "rx");
+	if (IS_ERR(dwmac->sgmii_rx))
+		return dev_err_probe(&pdev->dev, PTR_ERR(dwmac->sgmii_rx),
+				     "error getting sgmii rx clock\n");
+

The SGMII clock is optional...

Yes. RGMII do not have this clock.

Quoted 13 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c static int starfive_dwmac_probe(struct platform_device *pdev)

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c +3 -2
 	/* Generally, the rgmii_tx clock is provided by the internal clock,
 	 * which needs to match the corresponding clock frequency according
 	 * to different speeds. If the rgmii_tx clock is provided by the
 	 * external rgmii_rxin, there is no need to configure the clock
 	 * internally, because rgmii_rxin will be adaptively adjusted.
 	 */
-	if (!device_property_read_bool(&pdev->dev, "starfive,tx-use-rgmii-clk"))
-		plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate;
+	if (!device_property_read_bool(&pdev->dev, "starfive,tx-use-rgmii-clk")) {
+		if (plat_dat->phy_interface == PHY_INTERFACE_MODE_SGMII)
+			plat_dat->set_clk_tx_rate =

stmmac_starfive_sgmii_set_clk_rate;

Quoted 2 lines

So you probably want to return an error here if it is missing.

No. RGMII still using stmmac_set_clk_tx_rate

Quoted 4 lines

Or you might want to look at the compatible, and make the clock mandatory for this device.

Andrew

Okay I will check the rx clock whether exist .

author maintainer
#12 lore raw

PATCH 5/5 net: stmmac: starfive: Add STMMAC_FLAG_SPH_DISABLE flag

In reply to Minda Chen

Add default disable split header flag in all the starfive soc.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c +1 -1
index df7b2fc9989d..f6e5a2c4dc27 100644
@@ -143,7 +143,7 @@ static int starfive_dwmac_probe(struct platform_device *pdev)
 	}
 
 	dwmac->dev = &pdev->dev;
-	plat_dat->flags |= STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP;
+	plat_dat->flags |= (STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP | STMMAC_FLAG_SPH_DISABLE);
 	plat_dat->bsp_priv = dwmac;
 	plat_dat->dma_cfg->dche = true;
 
Signature · 1 line
2.17.1